lundi 15 octobre 2018

Why random event follow a specific pattern?

I have create a grid layout. It displays 100 balls. Initially, all the balls will be in a random position. For every 25 ms a ball will move some unit (this is common for all the balls) in a random direction. You can see this in action in below image

Sample output in GIF

Even though the direction of the balls are random, after some time all the balls are moving to a bottom right corner. This behavior is repeating ever-time. You can see this in the below image.

Sample 1

Sample 2

  • Why random event follow a specific pattern?
  • Are random numbers truly random?
  • Is there is a problem with c# random number generator?
  • Is there is any mathematical explanation for this?

C# Code

Random random = new Random();
var direction = random.NextDouble() * 360;
var ballTranslate = child.RenderTransform.TransformPoint(new Point(0, 0));
var x = ballTranslate.X;
var y = ballTranslate.Y;
var x1 = x + (parm.Speed * Math.Cos(direction));
while (x1 < 0 || x1 > (parm.CellSize * parm.NoOfSplit))
{
    direction = random.NextDouble() * 360;
    x1 = x + (parm.Speed * Math.Cos(direction));
}

var y1 = y + (parm.Speed * Math.Sin(direction));
while (y1 < 0 || y1 > (parm.CellSize * parm.NoOfSplit))
{
    direction = random.NextDouble() * 360;
    y1 = y + (parm.Speed * Math.Sin(direction));
}

TranslateTransform myTranslate = new TranslateTransform();
myTranslate.X = x1;
myTranslate.Y = y1;
child.RenderTransform = myTranslate;

Full Code

https://github.com/Vijay-Nirmal/ProjectChaos




Aucun commentaire:

Enregistrer un commentaire