I looked at a variant as follows

Code: Select all

`Sub RandomSeed( Byval algorithm as Byte = 0 )`

Dim As Ulong Seed

Asm

rdtsc ' Get a number from the processor

mov ebx, eax ' copy eax

bswap eax ' invert to get the fast changing end

xor eax, ebx

mov dword Ptr [Seed], eax ' store it in Seed

End Asm

Randomize Seed, algorithm

End Sub

Executing many RandomSeeds in quick succession and printing them gave a random looking distribution. Totalling 10^8 of them and normalizing by dividing by 2^32 gave an average closer to 0.5 that I have ever seen. Of course, that in of itself, does not prove good quality random numbers but not getting close to 0.5 proves non-randomness.

However, when I streamed the 32-bit seeds into PractRand it failed spectacularly at 1KB. So, the 32-bit seeds generated are not even close to being random.

It then dawned on me that we would be hard pressed to do better than the following:

Code: Select all

`Sub RandomSeed( Byval algorithm as Byte = 0 )`

Randomize , 5

Dim As Ulong Seed = Cast( Ulong, Rnd*(2^32) )

Randomize Seed, algorithm

End Sub

We cannot do this so easily in PowerBASIC because it does not have a cryptographic generator (#5) built in.

<smile>