How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the Miranda 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 Miranda 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 Miranda programming language
Source code in the miranda programming language
main :: [sys_message]
main = [Stdout (lay (map show numbers))]
where numbers = take 5 (randoms 6 seed)
seed = 675248
randoms :: num->num->[num]
randoms sz = tl . iterate (msq sz)
msq :: num->num->num
msq sz seed = sq div (10^(sz div 2)) mod 10^sz
where sq = seed^2
You may also check:How to resolve the algorithm Documentation step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the Oforth programming language
You may also check:How to resolve the algorithm Bitwise IO step by step in the OCaml programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Go programming language