Hey,
I have noticed when you use srand or rand you write:
rand() % 99 + 1
I was wondering about the 1, is it just tradition to use it or is it from 1-99?
Just because i was wondering how i could make it between say 20 and 40 etc
Hey,
I have noticed when you use srand or rand you write:
rand() % 99 + 1
I was wondering about the 1, is it just tradition to use it or is it from 1-99?
Just because i was wondering how i could make it between say 20 and 40 etc
A solution to what you desire is given pretty much straight away, but it makes an interesting read -- http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx
It's not, however, a question about srand. That merely 'seeds' rand. You want to get random numbers which is rand.
Ok thank you, sorry for the mistake :S
I skimmed the article, but is the only problem with rand() that RAND_MAX may not be one less than a multiple of your maximum? Like if you do rand()%3, and RAND_MAX+1 is a multiple of 3, will that be truly random?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.