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!
Jump to Post
randNum = (rand() % range) + firstNum;
range is the total number you want to generate
firstnum is the beginning number of that range
All 6 Replies
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.