For part of a programming that I'm writing, I want to generate random numbers between the range of -1000 and 1000. My teacher never spent much time on the rand function, and I'm not quite sure how to specify a range like that. Any help would be greatly appreciated. Thanks!
rfrapp
17
Junior Poster in Training
Recommended Answers
Jump to PostrandNum = (rand() % range) + firstNum;
range is the total number you want to generate
firstnum is the beginning number of that range
Jump to PostWhat Walt P said basically sums it up =)
I took off my answer so you could think a little bit harder for yourself =P
All 6 Replies
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
skorm909
0
Junior Poster
mrnutty
761
Senior Poster
rfrapp
17
Junior Poster in Training
rfrapp
17
Junior Poster in Training
skorm909
0
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.