How to resolve the algorithm Random number generator (included) step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Random number generator (included) step by step in the Quackery programming language
Table of Contents
Problem Statement
The task is to: Note: the task is not to create an RNG, but to report on the languages in-built RNG that would be the most likely RNG used. The main types of pseudo-random number generator (PRNG) that are in use are the Linear Congruential Generator (LCG), and the Generalized Feedback Shift Register (GFSR), (of which the Mersenne twister generator is a subclass). The last main type is where the output of one of the previous ones (typically a Mersenne twister) is fed through a cryptographic hash function to maximize unpredictability of individual bits. Note that neither LCGs nor GFSRs should be used for the most demanding applications (cryptography) without additional steps.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Random number generator (included) step by step in the Quackery programming language
Source code in the quackery programming language
typedef unsigned long long u8;
typedef struct ranctx { u8 a; u8 b; u8 c; u8 d; } ranctx;
#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
u8 ranval( ranctx *x ) {
u8 e = x->a - rot(x->b, 7);
x->a = x->b ^ rot(x->c, 13);
x->b = x->c + rot(x->d, 37);
x->c = x->d + e;
x->d = e + x->a;
return x->d;
}
void raninit( ranctx *x, u8 seed ) {
u8 i;
x->a = 0xf1ea5eed, x->b = x->c = x->d = seed;
for (i=0; i<20; ++i) {
(void)ranval(x);
}
}
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the BASIC programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the Elena programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the PL/I programming language
You may also check:How to resolve the algorithm Apply a digital filter (direct form II transposed) step by step in the Haskell programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the SAS programming language