OutFile "Random.exe" Name "Random" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Usage: ; Push Seed (or previously generated number) ; Call RandomNumber ; Pop Generated Random Number Function RandomNumber Exch $R0 IntOp $R0 $R0 * "13" IntOp $R0 $R0 + "3" IntOp $R0 $R0 % "1048576" ; Values goes from 0 to 1048576 (2^20) Exch $R0 FunctionEnd ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Usage: ; Push Seed (or previously generated number) ; Push MaxValue ; Call RandomNumber ; Pop Generated Random Number ; Pop NewSeed Function LimitedRandomNumber Exch $R3 ;Max (later this is used to store the random number) Exch Exch $R4 ;Seed push $R2 ;Current Value push $R1 ;Current pos (-) push $R0 ;Current Random push $R5 ;Current pos push $R6 ;Max value (copy of $R3) push $R7 ;Random[0] value push $R8 ;Max[0] value StrLen $R1 $R3 StrLen $R7 $R3 StrCpy $R6 $R3 StrCpy $R3 "" StrCpy $R5 "1" strCpy $R8 $R6 1 ;Gets the first val and stores it in $R7 Push $R4 ;Seed RandomLoop1: Call RandomNumber Pop $R4 strlen $R0 $R4 intop $R0 $R0 / "2" strcpy $R0 $R4 1 $R0 strcpy $R2 $R6 1 IntCmp $R0 $R2 +1 +1 NewRandom1 StrCpy $R3 $R0 StrCpy $R7 $R0 IntOp $R1 $R1 - "1" IntCmp $R1 "0" EndRandom Goto Step2 NewRandom1: Push $R4 ;The new seed Goto RandomLoop1 Step2: ;Now get the other numbers Push $R4 ;The new seed RandomLoop: Call RandomNumber Pop $R4 strlen $R0 $R4 intop $R0 $R0 / "2" strcpy $R0 $R4 1 $R0 strcpy $R2 $R6 1 $R5 IntCmp $R7 $R8 +1 +2 IntCmp $R0 $R2 +1 +1 NewRandom StrCpy $R3 "$R3$R0" IntOp $R1 $R1 - "1" IntOp $R5 $R5 + "1" IntCmp $R1 "0" EndRandom NewRandom: Push $R4 ;The new seed Goto RandomLoop EndRandom: IntOp $R3 $R3 + "0" ;this is to delete possible initial 0's pop $R8 pop $R7 pop $R6 pop $R5 pop $R0 pop $R1 pop $R2 Exch $R4 Exch Exch $R3 FunctionEnd Section "" Push $HWNDPARENT ;Seed Loop: Push 99 ;Max Random Number Call LimitedRandomNumber pop $R0 ;Random Number pop $R1 ;New Seed MessageBox MB_YESNO "Random=$R0;Seed=$R1" IDNO +3 push $R1 Goto Loop SectionEnd