How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the XPL0 programming language
Table of Contents
Problem Statement
To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number in the sequence and returned as the result. This process is then repeated to generate more numbers. numbers (6 digits) as shown above.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the XPL0 programming language
Source code in the xpl0 programming language
real Seed;
func Random;
[Seed:= Floor(Mod(Seed*Seed/1e3, 1e6));
return fix(Seed);
];
int N;
[Seed:= 675248.;
for N:= 1 to 5 do
[IntOut(0, Random); ChOut(0, ^ )];
]
You may also check:How to resolve the algorithm Zumkeller numbers step by step in the zkl programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the GFA Basic programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the HicEst programming language
You may also check:How to resolve the algorithm Entropy step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Achilles numbers step by step in the FreeBASIC programming language