Skip to content

Commit

Permalink
Create CiaccoRandom.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaccoDavide committed Apr 22, 2018
1 parent 6be9b4a commit f57326d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src_Unity3D/CiaccoRandom.cs
@@ -0,0 +1,35 @@
using UnityEngine;
using System.Collections;

public class CiaccoRandom
{

private static int superSeed = 0;

public CiaccoRandom()
{

}

public void setSeed(int seed)
{
// seed can only be positive and seed range is [0 -> 9999998] seed=9999999 schould give the same as seed=0
superSeed = Mathf.Abs(seed) % 9999999 + 1;
// init for randomness fairness
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
superSeed = (superSeed * 125) % 2796203;
}

public int getRand(int min, int max) // both included: getRand(0,1) will return 0s and 1s
{
superSeed = (superSeed * 125) % 2796203;
return superSeed % (max - min + 1) + min;
}
}

0 comments on commit f57326d

Please sign in to comment.