A few questions...

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

A few questions...

Post by RayBritton »

Hi i have a few questions which are:
1)Is there anyway of limiting the numbers that varibles can get (no?)
2)What does RANDOMIZE do, that effects RND
3)In the Subs/Functions menu there are numbers after the name, what do they mean?

Thanks
RyanKelly
Coder
Posts: 48
Joined: Sun Jan 22, 2006 6:40 pm
Contact:

Post by RyanKelly »

1. No. You have to do this manually.
2. The random number generator applies an algorithm to a sequence of numbers. If it starts with the same "seed" you get the same series of numbers from the rnd function. RANDOMIZE sets the seed.
3. I think those numbers indicate the amount of memory in kilobytes that the procedure occupies after it has been translated to pcode by the interpretor.
RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton »

thanks
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

randomize

Post by Zim »

Randomize re-seeds the random number generator (RNG) but it doesn't "set" the seed. For example:

Code: Select all

randomize 555
print rnd
randomize 555
print rnd
would be expected to return the same number, but it doesn't. Here's the output from QB 3
  • .9563706
    .1887001
You'll get other numbers from QB 4, but they'll both still be different.
(Note: if you restart the program, you'll get the same two numbers.)

if you want to actually SET the seed to, say "555" you have to do this:

Code: Select all

dummy=rnd(-555)
From this point on the sequence you get will be the one starting with "555" as a seed.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

For the record, Im pretty sure QB running on windows follows this function to generate random numbers:

rand = (seed * 214013 + 2531011) MOD 16777216
seed = rand

whereas the last random number generated is the new seed.
But when we would ask QB for an actual random munber... it returns this instead(frand = rand number that RND returns)

rand = (seed * 214013 + 2531011) MOD 16777216
seed = rand
frand = rand / 16777216

So the new seed isnt actually that number between 0 and 1, its a different number but not the one thet gets returned to us.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
Post Reply