-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path26random.py
50 lines (29 loc) · 1005 Bytes
/
26random.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# A program is determinisitic if it is known what the outcome will
# be. It in indeterministic if you don't know what the result will be -
# this type is not so common, but is useful in games and other things.
# In programming it is really hard to get true random, but
# there is a built in module that gives us something really really
# close to random, which is really good enough for nearly any
# practical use.
# Example
# Use the random module
import random
for i in range(15)
x = random.random()
print x
# Random Integer
# The function randint() takes two numbers and generates a random number
# between the two
random.randint(3, 17)
random.randint(6, 15)
# Random Choice
# random.choice() lets you select a random object out of a set
# Example
myList = [4, 5, 6]
random.choice(myList)
# >>> 6
random.choice(myList)
# >>> 5
# The random module also has functions to generate random values
# from continuous distributions, including Gaussian, expoenential,
# gamma and more