@Fred: Questions about RandomSeed(), Random()

Everything else that doesn't fall into one of the other PB categories.
User avatar
Hades
Enthusiast
Enthusiast
Posts: 188
Joined: Tue May 17, 2005 8:39 pm

@Fred: Questions about RandomSeed(), Random()

Post 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
User avatar
Hades
Enthusiast
Enthusiast
Posts: 188
Joined: Tue May 17, 2005 8:39 pm

Post by Hades »

Still no answer...
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: @Fred: Questions about RandomSeed(), Random()

Post 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)
Please correct my english
http://purebasic.developpez.com/
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
User avatar
Hades
Enthusiast
Enthusiast
Posts: 188
Joined: Tue May 17, 2005 8:39 pm

Post 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?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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
@}--`--,-- A rose by any other name ..
User avatar
Hades
Enthusiast
Enthusiast
Posts: 188
Joined: Tue May 17, 2005 8:39 pm

Post 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?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I didn't say it was easy to test if it was good, only if it produces repeatable results.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
User avatar
Hades
Enthusiast
Enthusiast
Posts: 188
Joined: Tue May 17, 2005 8:39 pm

Post by Hades »

Oh no, thanks. I don't want to kill your CPU. :D

Would be easier just to implement a Mersenne Twister. :wink: :D
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Hades wrote:Oh no, thanks. I don't want to kill your CPU. :D
:D

Actually, I was rather thinking of it happening on your gear. ;)
@}--`--,-- A rose by any other name ..
User avatar
Hades
Enthusiast
Enthusiast
Posts: 188
Joined: Tue May 17, 2005 8:39 pm

Post by Hades »

:oops:

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'. :lol:
Last edited by Hades on Tue May 02, 2006 5:47 pm, edited 1 time in total.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

:D
@}--`--,-- A rose by any other name ..
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

PS: though is different than thought. You got a typo or I am blind.

EDIT: @Dare2: Grrrrrrrrr!!!!!
Post Reply