vintage-basic.net
June 17, 2021, 05:05:11 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Random Integer FN  (Read 13854 times)
rdc
Newbie
*
Posts: 13


View Profile Email
« on: December 25, 2009, 08:00:06 AM »

I did a little random integer FN that might be useful:

Code:
5 REM A LITTLE INTEGER RANDOM FUNC: S = SEED, L = LOW VAL, H = HIGH VAL
10 RANDOMIZE
20 DEF FN RN(S, L, H) = INT((H - L + 1) * RND(S) + L)
25 PRINT "NUMBERS FROM 1 TO 10"
30 FOR I = 1 TO 10
40 PRINT FN RN(1, 1, 10)
50 NEXT I
55 PRINT "NUMBERS FROM 10 TO 20"
60 FOR I = 1 TO 10
70 PRINT FN RN(3, 10, 20)
80 NEXT I

Logged
Lyle Kopnicky
Administrator
Newbie
*****
Posts: 7


View Profile Email
« Reply #1 on: December 25, 2009, 12:17:30 PM »

Yes, that works great, rdc, thanks! It's very good for picking cards or rolling dice in games. Please note that most BASICs of the era did not support multiple arguments in user-defined functions. I saw no issue with compatibility, so Vintage BASIC supports multiple arguments, and also supports string arguments.
Logged
rdc
Newbie
*
Posts: 13


View Profile Email
« Reply #2 on: December 26, 2009, 10:07:54 AM »

Thanks. This is my standard "roll the dice" function I use in other languages. I am glad you implemented multiple arguments as that makes it much easier to create pseudo-functions and use them in the code.

Being an old guy I am enjoying messing around with Vintage. The only thing I am really missing is a Locate statement, but I understand that it wasn't part of the original Basic language used during the time that the Big Book came out. Although I haven't tried it yet, I think I can fake Locate using an array of strings the same size as the screen and just print the array when needed. This way you can create screen-type programs like the old Robots game. Now that I am thinking of it, I may just try and create a Robots game and see how it goes.

I should say that I saw Vintage on the Basic Programming site so I am glad E.K. mentioned it. You have really done a great job with this, and I am enjoying revisiting my past (which is probably just a another sign of old age). Smiley
Logged
E.K.Virtanen
Newbie
*
Posts: 11


312576736 lurah@luukku.com
View Profile WWW Email
« Reply #3 on: December 27, 2009, 09:36:20 AM »

I should say that I saw Vintage on the Basic Programming site so I am glad E.K. mentioned it.

["commercial brake"]
http://forum.basicprogramming.org/index.php/topic,1166.0.html
["/commercial brake"]  Roll Eyes

[edit]
@rdc; Nice piece of code. Known rdc quality Smiley
Logged

rdc
Newbie
*
Posts: 13


View Profile Email
« Reply #4 on: December 27, 2009, 04:37:36 PM »

LOL. Thanks man.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!