int i; do { i = 5 * (rand5() - 1) + rand5(); // i is now uniformly random between 1 and 25 } while(i > 21); // i is now uniformly random between 1 and 21 return i % 7 + 1; // result is now uniformly random between 1 and 7
Generate random number form 1 - 100 with probability of 1/100.You are not allowed to used rand() function. Any simple way of achieving above with using any complex implementation of random number generators algorithm.