dimanche 23 mai 2021

C++ random number -infinity to +infinity

This is my code

For (int i = 0; i < 10000; i++) {
    random2 = (1.0 * rand() / RAND_MAX);

    if (random2 >= 0.5)
    {
        random = (1.0 * rand() / RAND_MAX);
    }
    else {
        random = -(1.0 * rand() / RAND_MAX);
    }

} I want to get a random number between -infinity and+infinity 10000 times.

I tries -1 between 1 to get a random number. but I need -infinity between +infinity random number. this is my best please give me your wisdom




Aucun commentaire:

Enregistrer un commentaire