+ 2

I have created an algorithm for generating random numbers, however even after making provisions there are problems! Help me

Even after making provisions that the number doesn't exceed the seed and it doesn't become negative, I am still getting numbers exceeding the seed and negative numbers too. https://code.sololearn.com/WECN7NWn1b5F/?ref=app

15th Jun 2017, 4:59 AM
Prabhakar Dev
Prabhakar Dev - avatar
2 odpowiedzi
+ 1
Thanks
15th Jun 2017, 6:42 AM
Prabhakar Dev
Prabhakar Dev - avatar
0
I didn't get negative numbers, but imagine you got -150 in your first step. That's lower than 4, so it skips the while loop. After that, as it's negative, you invert it to 150. That's the reason for your seed exceed.
15th Jun 2017, 6:18 AM
merkrafter