0

Why is one is added for finding a random variable in a specific range like

for finding random variable within 8 we type cout code as cout>>1+rand()%8;

19th Jul 2018, 9:30 PM
Hemanth
Hemanth - avatar
5 ответов
+ 1
Note, this shifts the entire range +1 (0..7 becomes 1..8)
19th Jul 2018, 11:38 PM
Kirk Schafer
Kirk Schafer - avatar
0
in case the remainder is 0 and you don't want it to be 0
19th Jul 2018, 9:53 PM
hinanawi
hinanawi - avatar
0
thanks
19th Jul 2018, 10:20 PM
Hemanth
Hemanth - avatar
0
what diff do we get if it is shifted or not
20th Jul 2018, 1:48 AM
Hemanth
Hemanth - avatar
0
Hemanth without the +1 the range is 0 to 7, with it it's 1 to 8
20th Jul 2018, 6:51 AM
hinanawi
hinanawi - avatar