Question

How to pick a random number in C / C++?


Annonce
Ad

Answer

#include <time.h>
#include <stdlib.h>

int main()
{
    // Initialization, should only be called once
    srand(time(NULL));
    
    // pseudo-random integer between 0 and RAND_MAX
    int r = rand();      
}


[source]
# ID Query