![]() |
random variable function? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: random variable function? (/thread-21642.html) |
random variable function? - Novice_fanatic - Oct-08-2019 Hi, I was wondering if there is a 'random variable function' in the data base somewhere and if so, what is the name for it? I've used the 'random integer function' which is great, which was located in 'from random import randint' (with randint being the functions name). thank you. RE: random variable function? - buran - Oct-08-2019 what ranfom variable function should do? Maybe look at random.choice()
RE: random variable function? - Aurthor_King_of_the_Brittons - Oct-08-2019 The following will randomly select from a predetermined list of your choosing. I'm not sure if that helps. def main(): import random varList = ['ab','bb','cb'] ranVariable = random.sample(varList, 1) print(ranVariable) main() RE: random variable function? - Novice_fanatic - Oct-08-2019 Thank you guys, appreciate it RE: random variable function? - jefsummers - Oct-08-2019 Not sure what random variable function means - the typical float between 0 and 1 as in other languages? Rather than guess - here is a tip for seeing what functions may be available in a particular module import random dir(random)Getting a dir (directory) on an imported module lists the functions Jumping to the items that don't have an underline at the beginning, you see choice that was mentioned earlier, but also random (which is the 0-1 function), gauss, lognormvariate, and a wide range of random distributions to pull from. Very cool. So, you now want to know what randrange does. help(random.randrange) Probably you want random, But it is good to know there are lots of alternatives and the built in dir and help functions will give you direction.
|