How to generate 2 numbers so that 1 number is necessarily less than the 2nd. The rand function always generates the same numbers.
- Please provide a piece of your problem code - sys_dev
|
2 answers
Create a generation on the side, from system time in milliseconds.
Generate the first number.
Generate the second number, find the module from the division by the first.
r1 = srand(GetTickCount()); r2 = srand(GetTickCount()); r2%=r1; - And if r2 <r1? - BuilderC
- r1 = 77 r2 = 66 (r2 / r1) mod = 0 r2% r1 = r2 - (((r2 / r1) mod) * r1 Answer: if r2 <r1 then the number r2 will not change - Garden Chamber
|
x = rand(); y = rand(); y += y>=x; if (x>y) swap(x, y); |