Given a function that generates a random integer in the range of [0, MAX), write a function that gets an integer x as input and returns a random integer in [0, x).
Anonymous
This code should practically work: int rand(int x) { int num = MAX - (MAX % x); out = given_rand(); while (out >= num) out = given_rand(); return (out % x); }
Check out your Company Bowl for anonymous work chats.