##C++## unsigned int Rand4() { unsigned int r = Rand5(); while(r == 5) r = Rand5(); return(r); } unsigned int myRand2() { return((Rand4() - 1) & 1); } unsigned int Rand7() { return(((myRand2() << 2) | (myRand2() << 1) | myRand2()) + 1); } ---------- ###One-Liner### int Rand7(){int n=0;for(int i=0;i<3;++i){int r=Rand5();while(r==5) r=Rand5();--r;r&=1;n|=r<<i;} return n;} (Going for speed.)