1
00:00:05,160 --> 00:00:08,000
Hi, welcome to this new video.

2
00:00:08,000 --> 00:00:10,700
We're going to be switching
gears a little bit and talk

3
00:00:10,700 --> 00:00:13,160
about ways in which we

4
00:00:13,160 --> 00:00:16,425
could actually produce
information with randomness.

5
00:00:16,425 --> 00:00:19,100
We have learned how to,

6
00:00:19,100 --> 00:00:21,480
let's call it hard
code information,

7
00:00:21,480 --> 00:00:24,925
just by typing exactly
the numbers we want.

8
00:00:24,925 --> 00:00:27,640
We also learned how
to create sequences,

9
00:00:27,640 --> 00:00:30,195
numbers that follow
a sequential order.

10
00:00:30,195 --> 00:00:32,400
In the last video, we started
to learn that there are

11
00:00:32,400 --> 00:00:34,580
certain math equations that

12
00:00:34,580 --> 00:00:37,380
allow us to create
numbers through math.

13
00:00:37,380 --> 00:00:40,520
Those may be areas of
interest that each one of

14
00:00:40,520 --> 00:00:43,040
those might take you

15
00:00:43,040 --> 00:00:46,460
further into areas of
research and exploration.

16
00:00:46,460 --> 00:00:48,420
But there's a
different one as well,

17
00:00:48,420 --> 00:00:51,360
especially within computing
of how we could actually

18
00:00:51,360 --> 00:00:52,780
start considering
things that might

19
00:00:52,780 --> 00:00:54,460
be random or a pseudo random.

20
00:00:54,460 --> 00:00:57,040
As you could see, you'll
see that the computer has

21
00:00:57,040 --> 00:01:00,220
its own way of creating
a sense of randomness,

22
00:01:00,220 --> 00:01:03,000
even if it's not at
a fundamental level,

23
00:01:03,000 --> 00:01:05,020
a true form of randomness.

24
00:01:05,020 --> 00:01:07,900
But let's understand
randomness as we can

25
00:01:07,900 --> 00:01:11,135
actually use it within our
programming environment.

26
00:01:11,135 --> 00:01:17,815
Randomness creates a value

27
00:01:17,815 --> 00:01:20,400
that doesn't appear to have

28
00:01:20,400 --> 00:01:23,665
any pattern or
predictable behavior.

29
00:01:23,665 --> 00:01:26,860
If you have a range
or let's call them

30
00:01:26,860 --> 00:01:32,135
all the possibilities for a
value between here 1 and 8,

31
00:01:32,135 --> 00:01:36,725
selecting a random integer
from within that range,

32
00:01:36,725 --> 00:01:40,900
we'll yield one of those,
in this case five.

33
00:01:40,900 --> 00:01:44,010
But if we run that
function again,

34
00:01:44,010 --> 00:01:45,850
it will not be the same number.

35
00:01:45,850 --> 00:01:47,430
It could be five, again,

36
00:01:47,430 --> 00:01:51,490
there's nothing excluding
that old entry.

37
00:01:51,490 --> 00:01:55,170
But we will actually get
a new number every time.

38
00:01:55,170 --> 00:01:57,710
Within a loop, for instance,
if we think about it,

39
00:01:57,710 --> 00:01:59,910
if we use a random
function within a loop,

40
00:01:59,910 --> 00:02:01,565
every time that we
iterate over that loop,

41
00:02:01,565 --> 00:02:03,250
we will get a different result.

42
00:02:03,250 --> 00:02:06,250
That's quite interesting.

43
00:02:06,250 --> 00:02:09,060
What we will call all
these possibilities,

44
00:02:09,060 --> 00:02:12,330
we could actually start
thinking is the domain,

45
00:02:12,330 --> 00:02:13,965
We're creating a range,

46
00:02:13,965 --> 00:02:15,210
a domain in which

47
00:02:15,210 --> 00:02:18,840
these variables are,
we're sampling from.

48
00:02:18,840 --> 00:02:24,400
Let's see the syntax of how
do we use the random method.

49
00:02:24,400 --> 00:02:26,860
The first thing we
actually need to do

50
00:02:26,860 --> 00:02:29,600
is import the random module.

51
00:02:29,600 --> 00:02:31,460
We're introducing
something that is not by

52
00:02:31,460 --> 00:02:35,040
default part of our
programming environment,

53
00:02:35,780 --> 00:02:39,715
we will need to include
the import random.

54
00:02:39,715 --> 00:02:42,720
This is the very first module
that will start expanding

55
00:02:42,720 --> 00:02:46,360
upon the capabilities
of this environment,

56
00:02:46,360 --> 00:02:48,965
and you'll see that there's
many more as we go along.

57
00:02:48,965 --> 00:02:50,850
Now we can actually print,

58
00:02:50,850 --> 00:02:56,410
let's print the
variable random.random.

59
00:02:56,810 --> 00:02:59,390
This might feel confusing,

60
00:02:59,390 --> 00:03:04,080
but from the module random we
access the random function,

61
00:03:04,080 --> 00:03:09,105
and we will get this very
long decimal place number.

62
00:03:09,105 --> 00:03:11,395
But from that random module,

63
00:03:11,395 --> 00:03:15,010
we actually have a few
different versions or

64
00:03:15,010 --> 00:03:18,690
methods that we can use
within that module.

65
00:03:18,690 --> 00:03:21,820
For instance, from the
very same module random,

66
00:03:21,820 --> 00:03:24,390
we could use the randint module.

67
00:03:24,390 --> 00:03:30,010
We could give a domain
specifically here between 1-10

68
00:03:30,010 --> 00:03:32,195
and we will get

69
00:03:32,195 --> 00:03:37,240
10 or a random integer
from within that domain.

70
00:03:37,240 --> 00:03:40,460
We can do some
variations to specify,

71
00:03:40,460 --> 00:03:44,300
do we want a floating odd
number, do we want an integer?

72
00:03:44,300 --> 00:03:46,420
Let's just see how we
could actually implement

73
00:03:46,420 --> 00:03:48,820
this within our programming
environment and

74
00:03:48,820 --> 00:03:51,140
give some caveats for some
of the ways in which some of

75
00:03:51,140 --> 00:03:53,700
these random calculations
actually work.

76
00:03:53,700 --> 00:03:56,505
Here we are back in processing.

77
00:03:56,505 --> 00:04:02,320
We're not going to need a
draw loop in this example.

78
00:04:02,320 --> 00:04:07,515
Let's just go ahead and write
this within the set up.

79
00:04:07,515 --> 00:04:14,320
Let's just create a for loop
to start for equal in range.

80
00:04:16,460 --> 00:04:19,995
Let's do a 0-5,

81
00:04:19,995 --> 00:04:23,640
just a small number of numbers.

82
00:04:23,640 --> 00:04:27,075
Let's just create
our random numbers.

83
00:04:27,075 --> 00:04:29,640
Let's be specific.

84
00:04:29,640 --> 00:04:34,510
Let's just start with a
random integer number.

85
00:04:34,510 --> 00:04:36,790
Again, might take
you a little bit of

86
00:04:36,790 --> 00:04:38,250
time to write a long
variable like that,

87
00:04:38,250 --> 00:04:40,190
but it's worth remembering

88
00:04:40,190 --> 00:04:42,610
that this is in
fact being randomly

89
00:04:42,610 --> 00:04:48,230
generated and it's an
integer, random.randint.

90
00:04:51,070 --> 00:04:54,000
Let's do an experiment here.

91
00:04:54,000 --> 00:05:01,690
Let's just do 0 and 1.
Let's print this value.

92
00:05:03,710 --> 00:05:07,240
We're going to just
copy paste that.

93
00:05:09,740 --> 00:05:11,960
As you can see
here, we have a for

94
00:05:11,960 --> 00:05:15,950
loop that is
repeating five times.

95
00:05:15,950 --> 00:05:20,160
We are printing to the
console down here,

96
00:05:20,160 --> 00:05:24,680
the console will print the
value of that calculation.

97
00:05:25,990 --> 00:05:32,700
Let's just find a mistake.

98
00:05:33,740 --> 00:05:41,355
If you remember, we
have to import random.

99
00:05:41,355 --> 00:05:44,000
Make sure that you
import the module,

100
00:05:44,000 --> 00:05:45,340
otherwise you're going to run

101
00:05:45,340 --> 00:05:47,280
into errors as I'm doing here.

102
00:05:47,280 --> 00:05:52,020
Here we go. We have the module
imported. Now, the window.

103
00:05:52,020 --> 00:05:54,120
We're not going to be drawing
anything for a moment.

104
00:05:54,120 --> 00:05:57,060
Let's look at our
window and our console.

105
00:05:57,060 --> 00:06:04,510
Let's just try to navigate here.

106
00:06:04,510 --> 00:06:09,840
As you can see, we
have the numbers from

107
00:06:09,840 --> 00:06:17,615
0 and 1, both of those appear.

108
00:06:17,615 --> 00:06:20,190
We have it five times.

109
00:06:20,190 --> 00:06:21,720
Randomly, this could be a

110
00:06:21,720 --> 00:06:24,340
0 or a 1 because
it's an integer.

111
00:06:24,350 --> 00:06:26,610
Everything seems to
be working well.

112
00:06:26,610 --> 00:06:30,530
If we increase the
range of this integer,

113
00:06:30,530 --> 00:06:34,110
you'll get values that
go all the way up to 10.

114
00:06:34,110 --> 00:06:36,210
But what I wanted
to do is between

115
00:06:36,210 --> 00:06:39,355
0-1 because I wanted to
talk about inclusivity,

116
00:06:39,355 --> 00:06:46,515
meaning 0 and 1 are both
represented in the sequence.

117
00:06:46,515 --> 00:06:51,850
We might get unlucky if
we do a small sequence,

118
00:06:51,850 --> 00:06:53,740
but in general, both of

119
00:06:53,740 --> 00:06:56,020
those numbers should appear

120
00:06:56,020 --> 00:06:58,855
in the sequence when
we have a long list.

121
00:06:58,855 --> 00:07:05,400
But let's look at a different
way of calculating random.

122
00:07:05,400 --> 00:07:08,285
I'm just going to copy this line

123
00:07:08,285 --> 00:07:10,965
and comment the
previous one out.

124
00:07:10,965 --> 00:07:15,020
Let's call this
one random number.

125
00:07:17,270 --> 00:07:21,170
Here instead of using
a random integer,

126
00:07:21,170 --> 00:07:25,050
we're going to say randrange.

127
00:07:25,970 --> 00:07:29,950
A random range between 0 and 1.

128
00:07:30,170 --> 00:07:37,440
We are going to print the
second version of our random.

129
00:07:37,440 --> 00:07:42,230
Notice that what we're
actually getting here are

130
00:07:42,230 --> 00:07:47,280
all zeros. Why is that?

131
00:07:47,280 --> 00:07:49,180
Because, well, if we look at

132
00:07:49,180 --> 00:07:53,025
the documentation of
the randrange module,

133
00:07:53,025 --> 00:07:57,495
it uses an exclusive,

134
00:07:57,495 --> 00:08:00,030
meaning that between
these two values

135
00:08:00,030 --> 00:08:02,880
you will exclude
the second value.

136
00:08:02,880 --> 00:08:04,940
Meaning that it
will operate within

137
00:08:04,940 --> 00:08:07,335
the range determined by,

138
00:08:07,335 --> 00:08:11,455
let's say we do a 5,
between 0 and 4 here.

139
00:08:11,455 --> 00:08:15,305
But it will exclude
the number 5.

140
00:08:15,305 --> 00:08:18,560
It's important sometimes
when you start using some of

141
00:08:18,560 --> 00:08:19,980
these functions
that you understand

142
00:08:19,980 --> 00:08:21,705
reading the documentation,

143
00:08:21,705 --> 00:08:23,800
is it inclusive or

144
00:08:23,800 --> 00:08:26,580
is it exclusive of the
values that you're using?

145
00:08:26,580 --> 00:08:29,515
Specifically in the
random integer here,

146
00:08:29,515 --> 00:08:31,305
0 and 1, this

147
00:08:31,305 --> 00:08:33,180
is an operation that you
might want to do a lot,

148
00:08:33,180 --> 00:08:35,180
let's say if you have
two conditions and you

149
00:08:35,180 --> 00:08:37,395
might want to calculate if
something is on and off,

150
00:08:37,395 --> 00:08:39,840
maybe using a random integer,

151
00:08:39,840 --> 00:08:41,820
you might want to have maybe

152
00:08:41,820 --> 00:08:44,725
half of your values on and
some of your values off.

153
00:08:44,725 --> 00:08:47,020
Knowing if you're creating

154
00:08:47,020 --> 00:08:49,870
inclusive or inclusive random
might make the difference

155
00:08:49,870 --> 00:08:52,890
between all your cells or
all your flights being off,

156
00:08:52,890 --> 00:08:55,235
or just half of them, randomly.

157
00:08:55,235 --> 00:08:57,710
We're going to be using
these tools in the future.

158
00:08:57,710 --> 00:08:59,670
I just wanted to
not only use it,

159
00:08:59,670 --> 00:09:02,010
but show you that sometimes
you might run into

160
00:09:02,010 --> 00:09:05,970
bugs or issues by
implementing perhaps

161
00:09:05,970 --> 00:09:07,310
the wrong module or
the one that is not

162
00:09:07,310 --> 00:09:09,350
appropriate to the
thing that you're

163
00:09:09,350 --> 00:09:11,450
actually looking for,

164
00:09:11,450 --> 00:09:13,070
But again, this module is very

165
00:09:13,070 --> 00:09:16,510
useful and feel free
to kind of look into

166
00:09:16,510 --> 00:09:18,950
the documentation of
Random and see what

167
00:09:18,950 --> 00:09:20,910
other functions are available

168
00:09:20,910 --> 00:09:23,270
for you for your specific case.

169
00:09:23,270 --> 00:09:26,490
So yeah, I'll see you
in the next video.