QB / QB64 Discussion Forum     RULES     Other Subforums, Links and Downloads    Index of Threads

 

 Return to Index  

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

February 3 2012 at 1:05 AM
  (Login MCalkins)
R


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
This message has been edited by MCalkins on Aug 22, 2012 12:47 AM
This message has been edited by MCalkins on Aug 22, 2012 12:40 AM
This message has been edited by MCalkins on Feb 3, 2012 4:22 AM
This message has been edited by MCalkins on Feb 3, 2012 1:54 AM


 
 Respond to this message   
Response TitleAuthorDate
 Qbasic accepts SINGLE seeds Aug 22, 2012
  Where does it say that? Aug 22, 2012
   *by using the % symbol: RANDOMIZE [seed%]. I don't see where it says a range... Aug 22, 2012
    In 1.1 not 4.5 Aug 23, 2012
 * As indicated in the QB64 source code, the initial state is 0x50000. Feb 21, 2013
 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement