Creating random integers and floats randint randrange random and uniform

suggest change
import random

randint()

Returns a random integer between x and y (inclusive):

random.randint(x, y)

For example getting a random number between 1 and 8:

random.randint(1, 8) # Out: 8

randrange()

random.randrange has the same syntax as range and unlike random.randint, the last value is not inclusive:

random.randrange(100)       # Random integer between 0 and 99
random.randrange(20, 50)    # Random integer between 20 and 49
random.rangrange(10, 20, 3) # Random integer between 10 and 19 with step 3 (10, 13, 16 and 19)

random

Returns a random floating point number between 0 and 1:

random.random() # Out: 0.66486093215306317

uniform

Returns a random floating point number between x and y (inclusive):

random.uniform(1, 8) # Out: 3.726062641730108

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Random module:
* Creating random integers and floats randint randrange random and uniform

Table Of Contents
2 Filter
3 List
7 Loops
8 Random module
22 Reduce
27 Classes
31 Set
42 Tuple
45 Enum
62 Sockets
89 urllib
92 Idioms
104 Stack
105 Profiling
109 Logging
111 os module
118 Mixins
120 ArcPy
126 Arrays
132 2to3 tool
135 Unicode
138 Neo4j
140 Curses
141 Templates
145 heapq
146 tkinter
154 Audio
155 pyglet
157 ijson
160 Flask
161 Groupby
163 pygame
165 hashlib
166 Gzip
167 ctypes
185 pyaudio
186 shelve