jeudi 21 avril 2016

Random number generation in my implementation

Is this implementation of random number generation wrong?

int random_number(int l, int u)
{
    int num;
    num = rand()%u;
    if (num<l && num>u)
    {
        while(num<l && num>u)
        {
            num = rand()%u;
        }   
    }
    return num;
}

This is not giving me the correct answer. If I try random_number(4,8); it generates numbers like 0,1,2 etc.




Aucun commentaire:

Enregistrer un commentaire