7 kyu
PRNG: Linear Congruential Generator
247 of 457depperm
Description:
The Linear Congruential Generator (LCG) is one of the oldest pseudo random number generator functions.
The algorithm is as follows:
where:
a
/A
is the multiplier (we'll be using2
)c
/C
is the increment (we'll be using3
)m
/M
is the modulus (we'll be using10
)
is the seed.
Your task
Define a method random
/Random
in the class LCG
that provides the next random number based on a seed. You never return the initial seed value.
Similar to random return the result as a floating point number in the range [0.0, 1.0)
Example
# initialize the generator with seed = 5
LCG(5)
# first random number (seed = 5)
LCG.random() = 0.3 # (2 * 5 + 3) mod 10 = 3 --> return 0.3
# next random number (seed = 3)
LCG.random() = 0.9 # (2 * 3 + 3) mod 10 = 9 --> return 0.9
# next random number (seed = 9)
LCG.random() = 0.1
# next random number (seed = 1)
LCG.random() = 0.5
Algorithms
Similar Kata:
Stats:
Created | Jun 20, 2017 |
Published | Jun 20, 2017 |
Warriors Trained | 848 |
Total Skips | 16 |
Total Code Submissions | 1053 |
Total Times Completed | 457 |
Python Completions | 247 |
Crystal Completions | 11 |
Ruby Completions | 44 |
JavaScript Completions | 150 |
C# Completions | 58 |
Total Stars | 10 |
% of votes with a positive feedback rating | 85% of 142 |
Total "Very Satisfied" Votes | 110 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |