COMPUTER/C++

c, cpp 랜덤함수

2015. 11. 8. 00:16

#include <cstdlib>

rand()


#include <ctime>

srand((unsigned int)time(NULL));


N ~ ( M + N - 1 )

rand() % M + N


앞 ~ 뒤 ]

M = 뒤 - 앞 + 1

N = 앞


[0~9] rand()%10

[1~9] rand()%9+1

[10 ~ 99] rand()%90+10

+ Recent posts