If one needs genuinely unpredictable numbers one cannot use RND, there has to be an 'external' source of randomness, such as something derived from a truly random process like thermal noise. If you're lucky your Operating System may provide such a function, for example the Windows CryptGenRandom function.
Failing such an API function you could attempt to introduce unpredictability by for example timing how long it takes the user to press a key or how long it takes to retrieve data from a distant web site or something. These would be better than nothing but it would be hard to demonstrate that they really do introduce much 'entropy'.
Is there another way? It turns out that if you have a modern CPU it may provide a solution. Some x86 CPUs have the RDSEED instruction and some ARM CPUs the RNDR function; I don't know how they work internally but they claim to generate unpredictable random numbers. Here's a little program you can run in BB4W, BBCSDL or BBCTTY, when running on an x86 CPU (32 or 64 bits):
Code: Select all
DIM ]^P% 100
[OPT 2
.avail
mov eax, 7 ; set EAX to request function 7
xor ecx,ecx ; set ECX to request subfunction 0
cpuid
bt ebx, 18
sbb eax,eax
ret
.rdseed
db &0F : db &C7 : db &F8 ; rdseed eax
jnc rdseed
ret
]
IF NOT USR(avail) THEN PRINT "RDSEED instruction not available" : END
REPEAT
PRINT "Random integer = &" ; ~USR(rdseed)
WAIT 1
UNTIL FALSE
END