Ask coding questions

← Back to all posts
How can I use a variable in randrange()?
Imzecorella (2)

I want to use a variable in rangerange() but it seems that I can not do that. Any alternatives?
Example:
ACT = 5
from random import randrange
eACT = randrange(ACT)

Answered by Brendan23 (166) [earned 5 cycles]
View Answer
Comments
hotnewtop
Brendan23 (166)

@Imzecorella eACT = randrange(ACT) should work.

Brendan23 (166)

@Brendan23 there is a chance that 2 of the same number get chosen. if you increase ACT then there will be less chance of that.

Imzecorella (2)

@Brendan23 oops my bad, I used the same variable name twice without noticing, cossing a collision in values. My bad

Imzecorella (2)

*Python by the way