Page 1 of 2
@Fred: Questions about RandomSeed(), Random()
Posted: Sat Apr 29, 2006 5:28 am
by Hades
Hi Fred.
1. What values make sense for RandomSeed() ? (0..2^31-1 ?)
2. What is the highest useful value for Random() ? (2^31-1 ?)
3. Any hint what kind of PRNG you are using?
Have a nice day,
Hades
Posted: Tue May 02, 2006 4:28 pm
by Hades
Still no answer...
Re: @Fred: Questions about RandomSeed(), Random()
Posted: Tue May 02, 2006 4:38 pm
by Comtois
1. What values make sense for RandomSeed() ? (0..2^31-1 ?)
RandomSeed(ElapsedMilliseconds()) or use a long.
2. What is the highest useful value for Random() ? (2^31-1 ?)
$7FFFFFFF or +2147483647 (it's a signed long)
Posted: Tue May 02, 2006 4:43 pm
by Trond
Random() takes any number from 0 to 2147483647. (Quads are truncated.)
RandomSeed() takes any number from -2147483648 to 2147483647. I don't know whether it actually uses the entire range.
Posted: Tue May 02, 2006 4:53 pm
by Hades
Thank you for your answers.
to RandomSeed():
I have to be sure I can use at least 30 bit for the seed, and they are fully used by the PRNG (produce different, repeatable results). Does anybody know if that is the case?
Posted: Tue May 02, 2006 4:55 pm
by Trond
Hades wrote:Thank you for your answers.
to RandomSeed():
I have to be sure I can use at least 30 bit for the seed, and they are fully used by the PRNG (produce different, repeatable results). Does anybody know if that is the case?
If that is not the case it sounds like a bug, but you can always test it.
Posted: Tue May 02, 2006 5:01 pm
by Dare2
This ..
Code: Select all
RandomSeed(%111111111111111111111111111111)
For i = 1 To 20
Debug Random($7FFFFFFF)
Next
Always gives me this ..
- 1428841689
1400720876
2101687175
1376130085
509981955
1786875312
1012963906
743527194
1792047849
1862237268
1854146918
1918186864
634768099
2090250383
243859415
814637835
2055386557
230076762
681308473
415508342
And this..
Code: Select all
RandomSeed(%101010101010101010101010101010)
For i = 1 To 20
Debug Random($7FFFFFFF)
Next
Always gives me this..
- 694093175
733968713
375167596
360530968
1269931708
162140230
1154304316
127478278
734274873
904269346
496657588
969237289
142867284
1356160719
830562000
1422205369
1447137896
40352398
520117975
282751248
Posted: Tue May 02, 2006 5:02 pm
by Hades
@Trond
No, it wouldn't be a bug, just a weak random number generator.
And if it's a good generator it isn't that easy to test.
The easiest way would be an answer of Fred. He should know.
@Dare2
Ok, but how do I know that there aren't other seeds, that give the same numbers?
Posted: Tue May 02, 2006 5:08 pm
by Trond
I didn't say it was easy to test if it was good, only if it produces repeatable results.
Posted: Tue May 02, 2006 5:14 pm
by Dare2
Hades wrote:@Dare2
Ok, but how do I know that there aren't other seeds, that give the same numbers?
Only thought I have on that is looping from min to max random seed and getting the first few results from each. Store results, look for duplicates, if there are dupes, use these in a smaller test with a larger sample.
Not too trivial a file size, though.

But it would resolve your question for you.
Posted: Tue May 02, 2006 5:18 pm
by Hades
Oh no, thanks. I don't want to kill your CPU.
Would be easier just to implement a Mersenne Twister.

Posted: Tue May 02, 2006 5:26 pm
by Dare2
Hades wrote:Oh no, thanks. I don't want to kill your CPU.

Actually, I was rather thinking of it happening on your gear.

Posted: Tue May 02, 2006 5:37 pm
by Hades
I thought you said :
'Not too trivial a file size, though. But
I would resolve your question for you.'
Now I see you said 'it'.

Posted: Tue May 02, 2006 5:39 pm
by Dare2
Posted: Tue May 02, 2006 5:39 pm
by josku_x
PS: though is different than thought. You got a typo or I am blind.
EDIT: @Dare2: Grrrrrrrrr!!!!!