# I've borrowed Galleon's "randomize using"...

February 3 2012 at 1:05 AM
ASM Forum

Response to Here is a convincing demonstration of zombie's formula

DECLARE SUB qRandomizeUsing (s AS SINGLE)
DECLARE FUNCTION qRnd! ()
DIM SHARED qSeed AS LONG
qSeed = &H50000

SUB qRandomizeUsing (s AS SINGLE)
' derived from: QB64 0.942 win32: libqbx.cpp: sub_randomize
' this would be so much simpler with unsigned math

qSeed = CVL(RIGHT\$(MKD\$(s), 4))
qSeed = (((qSeed XOR INT(qSeed / &H10000)) AND &HFFFF&) * &H100)
END SUB

FUNCTION qRnd!
' derived from:
' http://www.network54.com/Forum/178387/message/1046747461/
' this would be so much simpler if overflow could be ignored.

DIM t AS DOUBLE
t = qSeed
t = (&HFD43FD * t + &HC39EC3)
qSeed = t - INT(t / &H1000000) * &H1000000
qRnd = qSeed / &H1000000
END FUNCTION

 This message has been edited by MCalkins on Feb 21, 2013 12:57 AM

 Respond to this message
 Response Title Author Date Qbasic accepts SINGLE seedsPage 1 2 3 4 5 Michael Calkins Aug 22, 2012 Where does it say that?Page 1 2 3 4 5 Clippy Aug 22, 2012 *by using the % symbol: RANDOMIZE [seed%]. I don't see where it says a range...Page 1 2 3 4 5 Michael Calkins Aug 22, 2012 In 1.1 not 4.5Page 1 2 3 4 5 Clippy Aug 23, 2012 * As indicated in the QB64 source code, the initial state is 0x50000.Page 1 2 3 4 5 Michael Calkins Feb 21, 2013 * or by PRINT HEX\$(RND(0) * 2 ^ 24)Page 1 2 3 4 5 Michael Calkins Mar 23, 2015