generate random number in a range c++ [duplicate]
问题 This question already has answers here : How does modulus and rand() work? (4 answers) Closed 5 years ago . I'm using the ncurses library to build a game. I'm having trouble generating the correct random numbers. The while loop below needs to keep generating random numbers until they are between 1 and 45(this is my y-axis limits on the standard screen). I can't figure out what I'm doing wrong because the while loop condition looks fine to me. The problem is that while loop starts running