Page 1 of 1

A few questions...

Posted: Sat Feb 18, 2006 7:59 am
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

Posted: Sat Feb 18, 2006 12:30 pm
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.

Posted: Sat Feb 18, 2006 12:31 pm
by RayBritton
thanks

randomize

Posted: Wed Feb 22, 2006 12:50 pm
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.

Posted: Wed Feb 22, 2006 7:41 pm
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.