+ 6
rand () and srand () .can anyone explain.
rand (). cstdlib
4 Respostas
+ 5
To generated random number you need to use rand() function and srand() function use to initialization of rand. Put your srand above if statement. And initialize rand by srand(time(NULL)).
You have to use ctime header file for time function. it would work perfect.
if you not initialized rand then, it will generate same number.
if you want it within a range use
rand()%(max-min+1)+min
Hope it helps you
+ 5
thanks for the help
I understand now
0
check out my code fun with true random nos , I ve included lots of helping comments, it will help
0
there are 2 types of random no. generator RNGs
1. Pseudo RNGs , that don't need any value and generate random no. s using 2 things
* cstdlib library &
*rand() function
but it's called pseudo coz it's less random in nature, can statistically determine the no.s
2. True RNGs, that need a seed value to generate best possible random no.s, hence called true
it uses 3 things
*cstdlib- the library that stores the functions
*srand(seed_value)- function to get any seed value, in my code example it's the age value.
rand()- to generate random no.s