Skip to main content
Commonmark migration
Source Link

##C++##

C++

int Rand4()
{
    int r = Rand5();
    return r > 4 ? Rand4() : r;
}

inline int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    int r = Rand8();
    return r > 7 ? Rand7() : r;
}

##C++ (109)##

C++ (109)

###Golfed###

Golfed

int Rand4(){int r=Rand5();return r>4?Rand4():r;}int Rand7(){int r=Rand4()-1<<2+Rand4();return r>7?Rand7():r;}

##C++##

int Rand4()
{
    int r = Rand5();
    return r > 4 ? Rand4() : r;
}

inline int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    int r = Rand8();
    return r > 7 ? Rand7() : r;
}

##C++ (109)##

###Golfed###

int Rand4(){int r=Rand5();return r>4?Rand4():r;}int Rand7(){int r=Rand4()-1<<2+Rand4();return r>7?Rand7():r;}

C++

int Rand4()
{
    int r = Rand5();
    return r > 4 ? Rand4() : r;
}

inline int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    int r = Rand8();
    return r > 7 ? Rand7() : r;
}

C++ (109)

Golfed

int Rand4(){int r=Rand5();return r>4?Rand4():r;}int Rand7(){int r=Rand4()-1<<2+Rand4();return r>7?Rand7():r;}
Recursive version cuts down on 1 character...
Source Link

##C++##

int Rand4()
{
    for(int r; (r = Rand5()) > 4;);
        ;
  return r 
 > 4 ? Rand4() return: r;
}

inline int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    for(int r; (r = Rand8()) > 7;);
        ;
  return r 
 > 7 ? Rand7() return: r;
}

##C++ (110109)##

###Golfed###

int Rand4(){for(int r;(r=Rand5())>4;);return r>4?Rand4(r);:r;}int Rand7(){for(int r;(r=Rand4()-1<<2+Rand4())>7;);return r>7?Rand7():r;}

##C++##

int Rand4()
{
    for(int r; (r = Rand5()) > 4;)
        ;
    
     return r;
}

int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    for(int r; (r = Rand8()) > 7;)
        ;
    
     return r;
}

##C++ (110)##

###Golfed###

int Rand4(){for(int r;(r=Rand5())>4;);return(r);}int Rand7(){for(int r;(r=Rand4()-1<<2+Rand4())>7;);return r;}

##C++##

int Rand4()
{
    int r = Rand5();
    return r > 4 ? Rand4() : r;
}

inline int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    int r = Rand8();
    return r > 7 ? Rand7() : r;
}

##C++ (109)##

###Golfed###

int Rand4(){int r=Rand5();return r>4?Rand4():r;}int Rand7(){int r=Rand4()-1<<2+Rand4();return r>7?Rand7():r;}
Actually returns 1...7 now.
Source Link

##C++##

unsigned int Rand4()
{
    unsigned for(int r; (r = Rand5();

    while(r) ==> 54;)
        r = Rand5();
    
    return(r); r;
}

unsigned int myRand2Rand8()
{    
    return( (Rand4() - 1) &<< 12 + Rand4();
}

unsigned int Rand7()
{
    return(for(int r; (myRand2r = Rand8()) <<> 27;) 
 | (myRand2() << 1) | myRand2()) + 1);
    
    return r;
}

##C++ (106110)##

###Golfed###

int Rand7Rand4(){for(int n=0;forr;(r=Rand5())>4;);return(r);}int i=0;i<3;++iRand7(){for(int r=Rand5r;();whiler=Rand4(r==5) r=Rand5-1<<2+Rand4();--r;r&=1;n|=r<<i;} return)>7;);return n;r;}

(Going for speed.)

##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);
}

##C++ (106)##

###Golfed###

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.)

##C++##

int Rand4()
{
    for(int r; (r = Rand5()) > 4;)
        ;
    
    return r;
}

int Rand8()
{    
    return (Rand4() - 1) << 2 + Rand4();
}

int Rand7()
{
    for(int r; (r = Rand8()) > 7;) 
        ;
    
    return r;
}

##C++ (110)##

###Golfed###

int Rand4(){for(int r;(r=Rand5())>4;);return(r);}int Rand7(){for(int r;(r=Rand4()-1<<2+Rand4())>7;);return r;}
deleted 20 characters in body
Source Link
Loading
added 30 characters in body
Source Link
Loading
added 18 characters in body
Source Link
Loading
added 129 characters in body; added 20 characters in body
Source Link
Loading
added 20 characters in body
Source Link
Loading
added 72 characters in body
Source Link
Loading
added 8 characters in body; added 24 characters in body
Source Link
Loading
added 17 characters in body
Source Link
Loading
Source Link
Loading