@Geoff: Try this then, I can't say for sure, but might work with that version:
REM Project: Derren Brown heads
REM Added alternative RNG implementation by Rudolpho
REM Created: 11/12/2013
REM Updated: 25/12/2013 » Merry Christmas!
#constant ole32 1
load dll "ole32.dll", ole32
Print " Flips in each of 25 trials (getting a run of 10)"
Print
Global highest = 1
Global lowest = 100000
Global Ptr
Ptr = make memory(16)
Randomize Timer()
For trials = 1 To 25
run=0
flips=0
Repeat
flips=flips+1
result = RandomUnsignedInteger(1)+1
If result=1 Then run=run+1
If result=2 Then run=0
Until run = 10
Print flips
If flips > highest Then highest = flips
If flips < lowest Then lowest = flips
Next trials
Print
Print "lowest= ",lowest
Print "highest= ",highest
Wait Key
delete memory Ptr
delete dll ole32
End
function RandomUnsignedInteger(maxValue as dword)
if maxValue = 0 then exitfunction 0
if maxValue = 1 then inc maxValue
rem Use global memory block for faster processing
pGuid = Ptr
if call dll(ole32, "CoCreateGuid", pGuid) <> 0
rem Failure, this shouldn't normally happen
exitfunction -1
endif
result = PeekByte(pGuid, 2) << 24 || PeekByte(pGuid, 6) << 16 || max((PeekByte(pGuid, 4) + PeekByte(pGuid, 1) + PeekByte(pGuid, 11) / 3), 0xff) << 8 || PeekByte(pGuid, 9)
result = abs(result mod maxValue) ` We don't want negative random numbers in this implementation
endfunction result
function PeekByte(ptr as dword, offset as integer)
inc ptr, offset / 4
bitOffset = (offset mod 4) * 8
iValue = *ptr
bValue = (iValue >> bitOffset) && 0x000000ff
endfunction bValue
Quote: "I think the RND will be far more reliable than looking into memory like that."
Since CoCreateGuid "guarantees" to generate a unique id for each call, it should do very well for producing random numbers (since that is most likely what it is based on to begin with).
Quote: "And since you free it before you look at it, you may get some run-time exceptions."
Where exactly did I do that?
"Why do programmers get Halloween and Christmas mixed up?" Because Oct(31) = Dec(25)