Forum Discussion
Function RandomNumber(Min, Max) Randomize RandomNumber = Int(Min + Rnd*(Max - Min + 1)) End Function
I tried to implement this logic using python , its not working
I tried as below
def RandomNumber(Min, Max)
Randomize
RandomNumber = Int(Min + Rnd*(Max - Min + 1))
Here am getting error in the second line ie. "Randomize" doesnt exist in python. Please advice
import random random.randint(min_, max_) #will return random integer between min_ and max_
In Python you should use a module random to operate random values.
- Colin_McCrae8 years agoCommunity Hero
Just to add to baxatob's reply re. Python random numbers ....
randint (his example) is inclusive. So will return a random integer from 0-9 (including 0 and 9). So, technically, "between" isn't quite accurate.
Also, you probably want to seed it. (Which is what the "randomize" statement in the VB version does.)
In Python, use "random.seed()" (in this form - with no value passed in - it will use current time as the seed) to avoid getting the same sequence of (pseudo) random numbers every time. See here: http://stackoverflow.com/questions/22639587/random-seed-what-does-it-do - if you want an explanation.
Related Content
Recent Discussions
- 19 hours ago