Expired Untitled RNG Codes: Avoid using outdated codes now
Random number generator (RNG) codes are algorithms used to produce sequences of numbers that appear random.
Types of RNGs
Linear Congruential Generators (LCGs): Simple and widely used, but can have predictable patterns if not implemented carefully.
Mersenne Twister: Provides a larger state space and longer period, making it suitable for more demanding applications.
Cryptographically Secure Pseudo-Random Number Generators (CSPRNGs): Designed to be unpredictable even to attackers with knowledge of the algorithm's internal state.
Code Examples (Conceptual)
LCG Example (Python):
def lcg(seed, a, c, m, n):
result = []
x = seed
for _ in range(n):
x = (a x + c) % m
*(x)
return result
Mersenne Twister (Conceptual): This is a more complex algorithm, typically provided by language-specific libraries (e.g., in Python).
Considerations
Period Length: The number of values generated before the sequence repeats. Longer periods are generally better.
Statistical Properties: The sequence should pass statistical tests for randomness.
Seed Value: The initial value that determines the sequence. Using the same seed will result in the same sequence.
Security: For security-sensitive applications, use a CSPRNG.