## [REBOL] Re: Notes on seeding 'random/seed (long)

### From: moliad:aei:ca at: 20-Mar-2004 22:37

thanks for this thesis on the randomizing of rebol Alan! another tidbit of information that wasn't obvious to realize! -MAx ----- Original Message ----- From: "alan parman" <[reboler--programmer--net]> To: <[rebol-list--rebol--com]> Sent: Saturday, March 20, 2004 10:08 PM Subject: [REBOL] Notes on seeding 'random/seed (long)> Here are some things I found out will working on 'random/secure and'random/seed that may be of help to others.> I wanted to completely utilize the time provided by 'now/precise as the seedfor 'random/seed.> (for some cryptography related scripts) > > (the following messages are from the escribe archives and console output isfrom view 1.2.5.3.1> >From an earlier question on using 'random Joel Neely wrote: > Date: Thu, 22 Aug 2002 15:09:45 > > "The documentation should state what types of values are acceptable > as seeds. I believe that you need to restrict yourself to date!, > time!, or integer! values for legitimate seeds." > > And Frank Sievertsen wrote: > [REBOL] Re: True Random > Date: Mon, 20 Aug 2001 00:09:35 > > Try this: > random/seed checksum form now/precise > > CU, > Frank > > With Petr Krenzelok adding: > Date: Mon, 20 Aug 2001 00:32:38 > > you can even use checksum/secure .... > > -pekr- > > But please observe the following... > > It appears that 'random/seed seeded with time ('now/precise) only seeds to thesecond! ...> randomize-series: func [series][ > random/seed now/precise > random/secure series > ] > > >> loop 10 [print [now/precise randomize-series "12345"]] > 15-Jan-2004/12:20:06.968-5:00 14532 > 15-Jan-2004/12:20:06.968-5:00 14532 > 15-Jan-2004/12:20:06.968-5:00 14532 > 15-Jan-2004/12:20:06.984-5:00 14532 > 15-Jan-2004/12:20:06.984-5:00 14532 > 15-Jan-2004/12:20:07-5:00 13524 > 15-Jan-2004/12:20:07-5:00 13524 > 15-Jan-2004/12:20:07.015-5:00 13524 > 15-Jan-2004/12:20:07.015-5:00 13524 > 15-Jan-2004/12:20:07.015-5:00 13524 > > ... as you see the randomized string only changes with the second. > > Changing the time to an integer won't work ... > > >> loop 10 [print [now/precise to-integer now/time/precise]] > 15-Jan-2004/12:13:32.953-5:00 44012 > 15-Jan-2004/12:13:32.968-5:00 44012 > 15-Jan-2004/12:13:32.968-5:00 44012 > 15-Jan-2004/12:13:32.968-5:00 44012 > 15-Jan-2004/12:13:32.984-5:00 44012 > 15-Jan-2004/12:13:32.984-5:00 44012 > 15-Jan-2004/12:13:33-5:00 44013 > 15-Jan-2004/12:13:33-5:00 44013 > 15-Jan-2004/12:13:33-5:00 44013 > 15-Jan-2004/12:13:33.015-5:00 44013 > > ... as you can see that the integer changes only with the second. > > Also, note that I only changed the time (not the date) to integer, because ... > > >> to-integer now/precise > ** Script Error: Invalid argument: 15-Jan-2004/12:30:15.734-5:00 > ** Where: to-integer > ** Near: to integer! :value > > ... thus not using the date portion in the potential seed. > > You cannot use checksum/secure on the time because ... > > >> random/seed checksum/secure form now/precise > == {=EEen|^E?^A"d=A6-=C2=EA/=CC^K^G=AC=D1=FD} > > ... and ... > > >> seed: checksum/secure form now/precise > == #{70C9F0D1D65FD88B6093DF38FD972ABCA56724B3} > >> random/seed seed > == "<`$-p*=C9=DF=BCg=D8=B3_=D6=A5=F08=FD"=D1" > >> random/seed seed > == "g<_=F0"=DF=C9`=BCp=FD=D1=D6=A5*$8-=B3=D8" > >> random/seed seed > == "=A5`=BC=D1_-p$=D8=F0<=FD=D6=C98*"=B3=DFg" > > ... returns a value! Thus the "seed" given above is scrambled , but not passedto random/seed as a seed.> If "checksum/secure form now/precise" was providing a legitimate seed then thefollwing sequences would be identical ...> >> seed: checksum/secure form now/precise > == #{70C9F0D1D65FD88B6093DF38FD972ABCA56724B3} > >> random/seed seed > == ""*g`=D1<=A5=BC=F0=B3=D8$=C98=D6_-p=DF=FD" > >> loop 5 [print random/secure "12345"] > 53142 > 31254 > 32514 > 25143 > 32145 > >> random/seed seed > == "*=FDg`=D6=D1=B3=DFp=C9-"$=A5=D8_8=BC=F0<" > >> loop 5 [print random/secure "12345"] > 32415 > 13524 > 15432 > 45231 > 43251 > > .. but they are not the same. > > So, to use _all_ of the information provided by 'now/precise (all of15-Jan-2004/12:34:16.437-5:00) as a seed to 'random/seed you must> random/seed to-integer checksum/secure form now/precise > > Now we see all the behavior we expect ... > > >> seed: to-integer checksum/secure form now/precise > == 1264002547 > >> random/seed seed > >> loop 5 [print random/secure "12345"] > 45213 > 41325 > 45321 > 35124 > 14523 > >> random/seed seed > >> loop 5 [print random/secure "12345"] > 45213 > 41325 > 45321 > 35124 > 14523 > > Notice that there is nothing returned when providing the seed and that the twosequences are identical.> > Other Observations: > > 'random/seed will take a date ... > > >> seed: now/date > == 16-Jan-2004 > >> random/seed seed > >> > > .. because nothing is returned. > > A 'binary is not a legitimate seed ... > > >> seed: to-binary 100 > == #{313030} > >> random/seed seed > == "010" > > ... because a value is returned. > > A 'time is a legitimate seed ... > > >> seed: now/time > == 22:11:03 > >> random/seed seed > >> > > ... but remember that it is good only to the second! > > So, you need to do two tests to determine if a seed is legitimate: > > 1) Nothing returned from 'random/seed your-seed > 2) Identical random sequences produced when reseeding from the same seed. > > To conclude: apparently only dates, times, and integers are legitimate seeds, > and one way to use all of a 'now (including both date and sub-secondprecision) is to> random/seed to-integer checksum/secure form now/precise > > Here's a handy function to reseed to sub-second precision ... > > randomize: func [ > {Reseed the random number generator using 'now/precise, or enter a date!time! integer! argument.}> seed [any-type!] > ][ > random/seed either value? 'seed [seed][to-integer checksum/secure formnow/precise]> ] > > As a bonus (as if this wasn't long enough already!) I have included mygleanings from the archives about 'random in the following binary!. Just decompress.