Simple random integer Random integer on device


A want to generate a random integer between 1 and 8. Is there any simple algorithm that works on device?
I hope there is a short function… but all random-number topics that i have read is soo difficult… :S

Depends on just how random this generator must be, how you will use it. FWIW, here’s what I did when my wife and I were on vacation and we lacked a pair of dice with which to play a board game, but we did have a hand calculator. Take any random interger and divide it by 8 and use the remainder. For example, 3105 / 8 (i.e. N is congruent to X mod 8). N is your assigned random interger and X is the whole number remainder which will be between 0 and 7. Of course you need a random interger to plug in. I had a scientific calculator so I took the square root of a random number (e.g. SR of, say, 12) and then used the four least significant digits for my assigned random integer. The idea is that square roots are almost always irrational so all digits will be non-repeating, they have no pattern. So if you just need the random number for recreational use, this will work for you even though it isn’t technically “random” in a pure mathematical sense.