As you can see, we are extracting only the fractional part of a sine wave. We have done this in the past. We can apreciate and understand how the ```sin()``` function that returns values between ```-1``` and ```1``` have been braked only and forced to be all positive values. We are going to use this effect for our purposes of achinving some random values by "breaking" this sine wave in smaller and smaller pieces. Why? by multiplying the ```sin(x)``` for bigger numbers. Go a head and click on the function and start adding some zeros.
By the time you get to 100000 ( and the equation looks like this: ```y = fract(sin(x)*100000.0)``` ) you probably are not hable to distinguish the sine wave any more. The granulary of the fractions have corrupt the flow of the sine in random chaos.
Using random could be hard, is both too chaotic and, sometimes, not random enought. Take a look to the following graph. Inside it, we are using a ```rand()``` fuction implemented exactly like we describe above.
Taking a closer look, you can se the ```sin()``` wave crest and though at -1s.5707 and 1.5707. I bet you know understand why. Also, if you see the distribution of it seem to be more likely to get values between 0.5 than on the edges.
<divclass="simpleFunction"data="y=rand(x);
//y = rand(x)*rand(x);
//y = sqrt(rand(x));
//y = pow(rand(x),5.);"></div>
A while ago [Pixelero](pixelero.wordpress.com) made an [interersting article about random distribution](https://pixelero.wordpress.com/2008/04/24/various-functions-and-various-distributions-with-mathrandom/). I add some of the function he use in the following lines of the previus graph for you to play and observe how the distribution changes. Un comment them and see how the distribution change.
If you read [Pixelero's article](https://pixelero.wordpress.com/2008/04/24/various-functions-and-various-distributions-with-mathrandom/) , is important to have in mind that our ```rand()``` function is a deterministic random or also known as pseudo-random. Which means, for example ```rand(1.)``` is going to return always the same value. [Pixelero](https://pixelero.wordpress.com/2008/04/24/various-functions-and-various-distributions-with-mathrandom/) makes reference to the ActionScript function ```Math.random()``` which is non-deterministic, every call will return a different value.
Now we understand better randomness, is time to apply it on both *x* and *y* axis. For that we need a way to transform a two dimensional vector into a one dimensional float point value. There are different ways to do this, but the ```dot()``` function can be very particulary helpfull in this case, becuse of it avility to return a float values between 0 and 1 depending if two vectors are align.
After scaling the space ten times more (line 10), we separate the integers of the coordenates from the fractions. We are familiar with this last operation because we have been usign it to subdevide a space in smaller cells that consistantly go from 0 to 1. By obtaining the integer of the coordinate we isolate a common value for all the threads inside a cell, to then use that integer to obtain a random value. Because the random is deterministic will be constant for all the pixels on that cell as long the random function is the same for all the threads.
Combining this two values will allow you to mix variation and order.
Take a look to this GLSL port of the famouse ```10 PRINT CHR$(205.5+RND(1)); : GOTO 10``` maze generator.
You can get an interesting variation by uncommenting the block of lines from 48 to 51. In case you want to animate it you can uncoment lines 33 and 34.
Using random aesthetically can be problematic. It's simply too chaotic and not really to many things looks ```random()``` in real life. Usually estocastic values are some how related to the previus one. If you look to a rain pattern, or the wallstreet chart (which both quite random), they are nothing like the random pattern we made at the begining of this chapter. The reason? Well random values have no correlation between them what so ever.
On the *Next* chapter we will learn about noise, the smooth and *natural looking* way of computational chaos.