Putting Random Number to Variable Issues

shThs

Пользователь
Регистрация
03.10.2018
Сообщения
117
Благодарностей
3
Баллы
18
Hi,

I am using the Random module to randomly pick the number 0 or 1, then place it to a variable. However, when I run the module, it produces the same outcome 0.

If I change the range from 0 - 10, it will pick a random number between that range.

Any clue as to why choosing the range 0 to 1 seems to always produce the outcome 0? I must have run this module over 100 times and the outcome is always 0. I simply want it to produce 0 or 1 at random and place it to the variable that I have assigned to it.

Thanks.

randomnumber.jpg
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 180
Баллы
113
Hi,

I am using the Random module to randomly pick the number 0 or 1, then place it to a variable. However, when I run the module, it produces the same outcome 0.

If I change the range from 0 - 10, it will pick a random number between that range.

Any clue as to why choosing the range 0 to 1 seems to always produce the outcome 0? I must have run this module over 100 times and the outcome is always 0. I simply want it to produce 0 or 1 at random and place it to the variable that I have assigned to it.

Thanks.

Посмотреть вложение 41126
0-10 will generate 0,1,2,3,4,5,6,7,8,9
0-1 will generate 0

That's how it works.
The last number in range will not be generated.
 

shThs

Пользователь
Регистрация
03.10.2018
Сообщения
117
Благодарностей
3
Баллы
18
That said, how do I produce an outcome of 0 or 1? The number 0 and number 1 that is being set to a variable needs to match a radio button with the number 0 and another with the number 1. I want it to randomly select one of these radio buttons with the number 0 or 1.
 

shThs

Пользователь
Регистрация
03.10.2018
Сообщения
117
Благодарностей
3
Баллы
18
Oh, I'm sorry. I re-read your statement where you state the last number will not be generated. In which case, I need to set my range from 0 - 2 to get an outcome of 0 or 1.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)