In python, is there anyway to have a variable be a different random number everytime?

Posted by woah113 on Stack Overflow See other posts from Stack Overflow or by woah113
Published on 2011-01-06T03:55:18Z Indexed on 2011/01/06 4:54 UTC
Read the original article Hit count: 219

Filed under:
|
|
|

Basically I have this:

import random
variable1 = random.randint(13, 19)

And basically what that does is assign variable1 a random number between 13 and 19. Great.

But, what I want it to do is assign a different random number between 13 and 19 to that variable every time it is called. Is there anyway I can do this?

If I'm not being clear enough here's an example:

import random
variable1 = random.randint(13, 19)
print(variable1)
print(variable1)
print(variable1)

And the output I want would look something like this:

./script.py
15
19
13

So yeah, anyway I could do this in python? (More specifically python3. but the answer would probably be similar to a python2 answer)

© Stack Overflow or respective owner

Related posts about python

Related posts about variables