This includes certificates (where it does nothing), but does not include any translations.
		
			
				
	
	
	
		
			3.2 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.2 KiB
		
	
	
	
	
	
	
	
id, title, challengeType, isHidden
| id | title | challengeType | isHidden | 
|---|---|---|---|
| 5e4ce2f5ac708cc68c1df261 | Linear congruential generator | 5 | false | 
Description
- $ r_0 $ is a seed.
- $r_1$, $r_2$, $r_3$, ..., are the random numbers.
- $a$, $c$, $m$ are constants.
Instructions
Tests
tests:
  - text: <code>linearCongGenerator</code> should be a function.
    testString: assert(typeof linearCongGenerator == 'function');
  - text: <code>linearCongGenerator(324, 1145, 177, 2148, 3)</code> should return a number.
    testString: assert(typeof linearCongGenerator(324, 1145, 177, 2148, 3) == 'number');
  - text: <code>linearCongGenerator(324, 1145, 177, 2148, 3)</code> should return <code>855</code>.
    testString: assert.equal(linearCongGenerator(324, 1145, 177, 2148, 3), 855);
  - text: <code>linearCongGenerator(234, 11245, 145, 83648, 4)</code> should return <code>1110</code>.
    testString: assert.equal(linearCongGenerator(234, 11245, 145, 83648, 4), 1110);
  - text: <code>linearCongGenerator(85, 11, 1234, 214748, 5)</code> should return <code>62217</code>.
    testString: assert.equal(linearCongGenerator(85, 11, 1234, 214748, 5), 62217);
  - text: <code>linearCongGenerator(0, 1103515245, 12345, 2147483648, 1)</code> should return <code>12345</code>.
    testString: assert.equal(linearCongGenerator(0, 1103515245, 12345, 2147483648, 1), 12345);
  - text: <code>linearCongGenerator(0, 1103515245, 12345, 2147483648, 2)</code> should return <code>1406932606</code>.
    testString: assert.equal(linearCongGenerator(0, 1103515245, 12345, 2147483648, 2), 1406932606);
Challenge Seed
function linearCongGenerator(r0, a, c, m, n) {
  // Good luck!
}
Solution
function linearCongGenerator(r0, a, c, m, n) {
    for (let i = 0; i < n; i++) {
        r0 = (a * r0 + c) % m;
    }
    return r0;
}