How to resolve the algorithm Pseudo-random numbers/Combined recursive generator MRG32k3a step by step in the uBasic/4tH programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pseudo-random numbers/Combined recursive generator MRG32k3a step by step in the uBasic/4tH programming language

Table of Contents

Problem Statement

numbers as shown above. are as shown above
repetitions of Is as follows:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pseudo-random numbers/Combined recursive generator MRG32k3a step by step in the uBasic/4tH programming language

Source code in the ubasic/4th programming language

@(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)


  

You may also check:How to resolve the algorithm Arithmetic/Rational step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Generator/Exponential step by step in the Elixir programming language
You may also check:How to resolve the algorithm Create a file step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Water collected between towers step by step in the Racket programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Delphi programming language