okay good morning here we are again um
this video we're going to focus on a
gaussian distribution of random numbers
now why is this something that matters
to us okay so we were looking at the
random Walker and that random Walker
made its little random movements all
around the around the window and we even
began to kind of take a little step with
that and say ah we could kind of adjust
probabilities instead of it having an
equal probability of going in any
direction at any moment we could say
it's going to be more likely to go to
the right or more likely to go up or
less likely to go down we could start to
control we could get control over the
randomness in our life right control
that's our goal here but really what one
of the things that I want to say in this
sort of section before we get into the
real motion and physics stuff we're
going to do in this video series is um
eliminate eliminate Randomness from your
life not forever but as an exercise to
yourself Randomness might have been a
bit of a crutch to you maybe maybe you
just you you learned how to draw stuff
in processing you learned how to move
things around the screen you said I
don't know it needs to be more Dynamic
let's just make it all random random
colors random shapes random positions
random speeds what we're doing here is
saying um is there a more thoughtful
approach we can take how can we um get
control over Randomness so we can
control the distribution of random
numbers we get or how can we create
algorithms to generate numbers in such a
way that we have a more organic set of
random numbers gaussian pearing noise
we're going to look at um a way of
customizing distribution of random
numbers with the Monte Carlo scenario so
we're going to look at a few different
things just as kind kind of again we're
just getting started here getting used
to back into using processing if you
haven't for a while before we get into
the real motion stuff so Gan
distributions of random numbers so
before I started this video I drew this
little mircat I spent I only spent about
45 minutes on it but I can't draw so
this I think is pretty good but um the a
mircat scenario came up in a previous
video let's say we're trying to make a
population of Mir cats that's our
simulation and we need Heights for them
so we
say
float h equals
random 100 comma 200 I'm picking a
random number between 100 and 200 that's
going to be my height well what's going
to happen I actually have an example
here that I want to run and what this
example is doing is it's picking a
random number associated with an exp
position on the screen and every time it
picks it it the the um rectangle starts
growing up and you can find this example
it's uh introduction uh example number
two random distribution so these numbers
are go these these These Bars are going
up and up you can see we have an even
distribution of random numbers there's
Randomness built in there but we're
getting uh this if we if we think about
this now in terms uh in terms of the
mircat that means if we were to graph
all of the Mir cats Heights from 100 to
200 if we picked random numbers a
perfect random number generator over an
infinite amount of time we'd get this
graph but this as we stated before is
perhaps not how it is in nature there
aren't there are probably actually I
don't again again I don't know anything
about Mir cats but if you look at human
beings there's you know most people are
about the same average height then
there's some people that are taller some
people are shorter very few people that
are really tall very few people that are
really short there is a normal
distribution of heights that word normal
also we use the word Gan for the
mathematician um this is a distribution
of random numbers that we find often in
nature or in test taking apparently the
bell curve you might have heard it out
there will be this will this will be on
the test there will be no test should
there be a test maybe there should be a
test I don't know why I drew that as
dotted lines so this is what that graph
looks like we want a lot of Mir cats
that have a height around the average
otherwise known as the
mean and then very few outliers but some
there's still always a chance so how do
we rewrite this code well one thing we
have to do is we have to at the top of
our code import a class and actually we
might add gussian random numbers into
processing which just for which I think
would make sense but for right now you
have to import this random class it
comes from java once you import that
class you can declare a random object
I'm going to call it a generator gen for
short a random number generator and as
with any object we've got to initialize
it as a new random a new object this
generator is now responsible for our
random numbers so instead of playing
float H give us a random number we can
say float H equals
gen. next
gussian
now let's actually put this into let's
make a little simple sketch for
ourselves and let's put this in and see
how far we
get okay now I'm going to make a new
processing sketch this is fun live
typing and we're going to
import java. ut. random this laptop is
on a pile of books it's very unstable I
need a laptop stand okay and uh uh we're
going to declare a random
generator and U make a window size oh
boy this is very hard to type I'm G to
have to fix this setup uh and uh here we
go background 255 so I don't know let's
pick let's see let's let's say float
H equals generator. next
gaussian and I don't know what just to
see what this
does let's tie this to the size of a
circle that will put in the middle of
the
window ah I I got to save this to
something somewhere okay uh I don't have
a system for this
yet uh Gan test sorry okay so this will
I'm standing in front of it the whole
time I I knew knew I was forgetting
something oh this is terrible this video
was going so well I thought but okay so
I'm just going to move this over fancy
or fancy system failed us okay so you
can see I typed in some basic stuff now
this gives me like when I lean against
the wall here gives me this like chill
scratch like nails on chalkboard okay
can I can get that out of my system okay
so ah so this didn't work can I convert
from double to float so this is a little
bit of an unfortunate thing which is
that the um Java class gives us a double
instead of float so I'm just going to
convert this to a float really quickly
and then run this and it says Ah it
doesn't want to do that for a double
because processing doesn't really have
anything to do with doubles so here we
go so I'm just going to change that to
the casting syntax and now we've got it
okay oh I see a little dot up there so
what did we get is that a normal
distribution they're all seem the same
it's the same it's drawing it over and
over again is it random is it not random
H what's going on okay so the thing that
we have to understand is
what are the numbers that come out of
this function well we did I got to shoot
I'm over here the thing we got to
remember is what are the numbers that
come out of this
function um okay so they here we gave
ourselves a range between 100 and 200 we
didn't give a range here what this does
is it gives us a gussian random number
with a
mean equal to zero and a standard
deviation equal to
one now mean we may perhaps we
understand already mean is the average
right this is that that Center maybe we
want our average to be 150 that's our
average height that we want um but what
does standard deviation mean now we
could go through some formulas and we
could look at how we calculate standard
deviation standard deviation we take all
of the heights we we get the difference
of the Heights from the average we
Square those we take the average of all
the squares then we take the square root
of that and and that's our uh standard
deviation blah blah blah so but I'm
going to give you some resources to if
you can look in the um nature of code
introduction chapter um it goes through
how to actually calculate standard
deviation but for us right now what I
want is just get sort of the feeling of
standard deviation because we can just
kind of play with it in our code and see
what kind of results we get um so what
is the feeling what is what does
standard deviation feel like to to you
here's what it feels like to me let's
draw that curve a number of different
ways I don't know that's probably pretty
good we can see this graph has a very
small standard deviation because just
about everything clusters around the
mean and nothing um varies from the mean
very much these there a lot of elements
vary from the mean a lot of elements
vary from the mean a lot of more
elements vary from the mean when you
have a large standard deviation you have
a lot of tall and short Mir cats when
you have a tiny standard deviation you
don't have have very many tall and short
ones you just got a lot of average ones
so we can use this number to play around
with how how much we're spreading out
from that mean how random are we really
getting how much more are we clustering
around that mean so how do we adjust for
that well if um so okay so if this gives
us a mean and standard deviation of one
we can always adjust by saying H equals
h plus what we want our mean to
be um right so we can only say if the
mean is zero but we want everything to
Cluster around 150 we can just add 150
to every single element now if we want
to spread or Shrink this standard
deviation spread it out or Shrink it
what we should do before
that is we should multiply by our own
I'm make a variable called STD DDE
standard deviation so once we get this
galin random number out of processing
with a mean of zero and the standard
deviation of one first we stretch it or
compress it by adjusting the standard
deviation by multiplying and then we
shift the whole graph over by adding the
mean to it um if this is confusing to
you which maybe it
is you can think of it this in
steps so let's look at this this sort of
GRA and this is zero and maybe maybe it
gave us this so first what we do is we
take this is our get ging Rand numbers
first we do is multiply let's say our
standard deviation is two and our uh a
our average is 100 so first we multiply
every number here by two and what we get
is a slightly wider graph we just
multiplied it so this number this is
pulls out because everything's
multiplied by two then what we do is we
add 100 to it so adding 100 to every
number we just shifted it over I kind of
widened it as well so that the average
is around 100 so this is the process we
can get that gussian random number out
stretch it move it adjust the standard
deviation adjust the mean let's go we'll
take a look at this now in our example
um if I walk back
here I can say h equals equal H times
I'm going to have a standard deviation
of 10 and I can say uh H = H + 100 so
the mean is 100 and we can see here
we're getting some random height random
sizes but this is very different than
just Randomness you can see they're kind
of clustering around one value um just
to just to pull up another example of
this uh which I want to grab from the
introduction
here um so this example is of
course forgot to have the import
statement in here this example is
picking a x location with every frame
and you can see it's then layering those
over top of each other and it gets
darker and darker around the center but
you see the outliers they're all do get
picked every once in a while and if we
look at this if we go into the code I
can't use this computer today um we can
see that here we have a a mean of the
middle of the screen and the standard
deviation of 60 so if I were to change
that standard deviation to
120 we now see we're getting we're
getting more and more outliers getting
picked if I change that standard
deviation to 10 then everything's really
getting picked right around the center
so you know that could be a variable it
could stretch shrink there's lots that
you could do with that so um so I I
think we're wrapping this up this is
actually a 12-minute video which is a
little bit longer than I imagined but
this is a bit of a tool and you can try
to think about so where could you apply
this for one maybe uh think about making
a design for a face and uh use Gan
distributions to design all those
elements so the the the nose the size
the position how could you make random
faces but all kind of appear within the
sort with with a gan distribution of
values another thing you might look is
at the random at the random Walker is
there a way you could use a gaussian
distribution of random numbers to pick
how a random Walker moves around the
screen and what would that sort of
visual result look like so um try to try
to look for something where you used
random in your code and instead of using
random use gaussian maybe um another
thing that just occurred to me is you
could think of uh if I were to splatter
paint here onto the wall would most of
the Paint Spot splatter in the center
and then there'd be some outliers could
you use gussian random numbers for that
and that didn't just occur to me I
thought of that beforehand but anyway it
occurred to me now to think of it to say
that okay so this video was a bit longer
than I had hoped and it was not nearly
as good as I'd hop but I'm just making
them and someday I'm going to uh remake
these and maybe you're going to email me
and tell me you should really remake it
okay I'm going to um press a button and
it's G to stop now okay uh here we go