About 317,000 results
Open links in new tab
  1. python - Generate random integers between 0 and 9 - Stack …

    Oct 22, 2010 · 2 If we look at their source implementations, random.randrange() (and random.randint() because it is the former's syntactic sugar) use a while-loop to generate a …

  2. Python random function - Stack Overflow

    Feb 21, 2013 · import random will import the random module whereas from random import random will specifically import the random function from the module. So you will be able to do …

  3. python - How to generate a random number with a specific …

    Jul 4, 2021 · import random num = random.randrange(1, 10**3) # using format num_with_zeros = '{:03}'.format(num) # using string's zfill num_with_zeros = str(num).zfill(3) Alternatively if you …

  4. python - Random int without importing 'random' - Stack Overflow

    Mar 20, 2021 · This will generate a list of uniformly distributed pseudo-random numbers between 0 and 1. Like the random number generators in random and numpy the sequence is fully …

  5. python - How to get a random number between a float range

    Oct 24, 2023 · import random random.uniform(a, b) # range [a, b) or [a, b] depending on floating-point rounding Python provides other distributions if you need. If you have numpy imported …

  6. Python Random Function without using random module

    May 7, 2025 · If getrandbits(k) returns k random bits then randint(a, b) should work as is (no skew due to modulo, etc). To test the quality of getrandbits(k), dieharder utility could be used: $ …

  7. Python: Random numbers into a list - Stack Overflow

    import random my_randoms = random.sample(range(100), 10) That generates numbers in the (inclusive) range from 0 to 99. If you want 1 to 100, you could use this (thanks to @martineau …

  8. Python "import random" Error - Stack Overflow

    import random number = random.randint(1,10000) Python gives me this error: File "C\Users\name\Documents\Python\random.py", line 5, in (module) print random.random() …

  9. python - How can I randomly select (choose) an item from a list …

    Nov 20, 2008 · NumPy solution: numpy.random.choice. For this question, it works the same as the accepted answer (import random; random.choice()), but I added it because the …

  10. Generate 'n' unique random numbers within a range [duplicate]

    Apr 3, 2014 · I know how to generate a random number within a range in Python. random.randint(numLow, numHigh) And I know I can put this in a loop to generate n amount of …

Refresh