Pseudo-random numbers/Combined recursive generator MRG32k3a: Difference between revisions

Content added Content deleted
(uBasic/4tH version added)
Line 1,128: Line 1,128:
3: 20059
3: 20059
4: 19931</pre>
4: 19931</pre>

=={{header|uBasic/4tH}}==
{{works with|v3.64}}
{{trans|C}}
Since uBasic/4tH has no floating point support, only the integer part of the task can be implemented.
<lang>@(0) = 0 ' First generator
@(1) = 1403580
@(2) = -810728
m = SHL(1, 32) - 209

@(3) = 527612 ' Second generator
@(4) = 0
@(5) = -1370589
n = SHL(1, 32) - 22853

d = SHL(1, 32) - 209 + 1 ' m + 1

Proc _Seed(1234567)
Print FUNC(_NextInt)
Print FUNC(_NextInt)
Print FUNC(_NextInt)
Print FUNC(_NextInt)
Print FUNC(_NextInt)
Print
End

_Mod Param(2)
Local(1)
c@ = a@ % b@
If c@ < 0 Then
If b@ < 0 Then
Return (c@-b@)
Else
Return (c@+b@)
Endif
EndIf
Return (c@)

_Seed Param(1) ' seed the PRNG
@(6) = a@
@(7) = 0
@(8) = 0

@(9) = a@
@(10) = 0
@(11) = 0
Return

_NextInt ' get the next random integer value
Local(3)

a@ = FUNC(_Mod((@(0) * @(6) + @(1) * @(7) + @(2) * @(8)), m))
b@ = FUNC(_Mod((@(3) * @(9) + @(4) * @(10) + @(5) * @(11)), n))
c@ = FUNC(_Mod(a@ - b@, m))

' keep last three values of the first generator
@(8) = @(7);
@(7) = @(6);
@(6) = a@;

' keep last three values of the second generator
@(11) = @(10);
@(10) = @(9);
@(9) = b@;

Return (c@ + 1)</lang>
{{out}}
<pre>1459213977
2827710106
4245671317
3877608661
2595287583


0 OK, 0:398
</pre>


=={{header|Wren}}==
=={{header|Wren}}==