You are given a random integer generator with the following implementation
- The first invocation always returns 1.
- The second invocation returns a random integer between 1 and 2.
- The third invocation returns a random integer between 1 and 3.
- The nth invocation returns a random integer between 1 and n, inclusive.
Based on the above function, write a random dice generator that is perfectly random, returning a value between 1 and 6 (inclusive) with equal probability.
- Your program/function should result in a random integer between 1 and 6, inclusive, in some usable form, i.e., to standard output or as a function return value.
- The ascending random number generator above can be defined as a "free" function in your program (i.e., doesn't count toward your character count), or a separate script/program that is executed as needed, assuming the state (
n) is persistent between calls.
- Assume that no more than 1000 dice rolls will ever be requested in a single use case of your program, and the initial random number generator can be reset to
1at the end of 1000 dice rolls to avoid overflow of
- Your program may not use any other source of random numbers except the ascending random generator defined above. You may of course request multiple random numbers from the random number generator for each single dice roll output.
- This is code-golf, so winner is shortest answer or most votes in the event of a tie. If you can generate 1000 dice rolls using less than 1000 generated random numbers, give yourself a 10-point efficiency bonus.
./asc-rand 1 # random integer between 1 and 1 ./asc-rand 1 # random integer between 1 and 2 ./asc-rand 3 # random integer between 1 and 3 ./asc-rand 4 # random integer between 1 and 4 # dice-gen generates random dice based on output of asc-rand program. ./dice-gen 3 ./dice-gen 6 ./dice-gen 5 ./dice-gen 1