-2

just started learning Python(2) and was wondering what the best way to make a Random Number Generator. I have made a very basic one so far with:

import random

for x in range(1):
    print random.randint(0,5)

I was wondering if there was a better way to do this with the ability to have numbers that are not integers generated. The end goal for this code is to make a random period of time pass in a game using time.sleep(x), would love to know if there is a better way of doing this.

bastantoine
  • 582
  • 4
  • 21
  • 4
    As an aside, you really should be learning Python 3. Python 3 came out over a decade ago, and Python 2 is officially passed its end of life. – juanpa.arrivillaga Mar 24 '20 at 11:17

1 Answers1

0

You can use random.unform:

def rand(start,end):
    return random.uniform(start,end)

or if you don't like random.uniform:

def rand(start,end):
    return random.random()*(end-start)+start
xkcdjerry
  • 965
  • 4
  • 15