├── .DS_Store ├── .gitignore ├── Assembly-CSharp-Editor-vs.csproj ├── Assembly-CSharp-Editor.csproj ├── Assembly-CSharp-Editor.pidb ├── Assembly-CSharp-vs.csproj ├── Assembly-CSharp.csproj ├── Assembly-CSharp.pidb ├── Assets ├── .DS_Store ├── Editor │ ├── MersenneDebugDrawing.cs │ └── MersenneDebugWindow.cs ├── Scenes │ └── SampleRandom.unity └── Scripts │ ├── UnityMersenneTwister.cs │ └── UnityNormalDistribution.cs ├── Library ├── AssetImportState ├── AssetVersioning.db ├── AudioManager.asset ├── BuildPlayer.prefs ├── BuildSettings.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── EditorUserBuildSettings.asset ├── InputManager.asset ├── InspectorExpandedItems.asset ├── MonoManager.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── ScriptMapper ├── TagManager.asset ├── TimeManager.asset ├── assetservercachev3 ├── expandedItems ├── guidmapper └── metadata │ ├── 32 │ └── 3249ce278b3bc4e34bc61a3b216de49b │ ├── 65 │ └── 65814e72818854fd2a54f1facb448af0 │ ├── 78 │ └── 78cde2e81b5e348a4acb0f80a4f64bb1 │ ├── 00 │ ├── 00000000000000001000000000000000 │ ├── 00000000000000002000000000000000 │ ├── 00000000000000003000000000000000 │ ├── 00000000000000004000000000000000 │ ├── 00000000000000005000000000000000 │ ├── 00000000000000006000000000000000 │ ├── 00000000000000007000000000000000 │ ├── 00000000000000008000000000000000 │ ├── 00000000000000009000000000000000 │ ├── 0000000000000000a000000000000000 │ ├── 0000000000000000b000000000000000 │ └── 0000000000000000c000000000000000 │ ├── 5a │ └── 5a5af9208f20d47c4bd06c20f668439e │ ├── c1 │ └── c14325ecf63c2a54f9069d125181eae1 │ ├── d4 │ └── d4a86cbe20e284ea8a7d8b61831e652e │ ├── dd │ └── dd1258601dba44313a1a7a0de637cee6 │ └── e2 │ └── e24b40a12e08947498ae05d50922f0c3 ├── Package └── TwisterAndNormalize.unitypackage ├── README ├── TestTwister-csharp.sln ├── TestTwister.sln └── TestTwister.userprefs /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #UPDATE: I assumed it would work for SVN and CVS 2 | #but dreamora pointed out that they would have issues 3 | #We use Git and currently have had no issues 4 | #Git is also Rad, I dont use SVN or CVS anymore unless I'm forced. 5 | 6 | #this is the git ignore file if you want to use the free Unity 7 | # the ! negates an ignore, so you ignore everything in Library then 8 | #un-ignore the metadata folder and those specific files 9 | #use at your own risk. 10 | 11 | #NOTE: this will cause your collaborators to re-import assets 12 | # (previews and cache), but it seems to have no value to keep in source control 13 | 14 | #I also wanted to note that Unity selling an asset server is retarded. 15 | #We already have awesome source control systems that we know are safe and 16 | #reliable. Why anyone would use the asset server is beyond me; why Unity felt the need to 17 | #recreate a well developed tool seems greedy. Focus on your product not on making things 18 | #more difficult for your users. 19 | 20 | Temp/* 21 | Library/* 22 | 23 | 24 | !Library/*.asset 25 | !Library/AssetImportState 26 | !Library/AssetVersioning.db 27 | !Library/BuildPlayer.prefs 28 | !Library/ScriptMapper 29 | !Library/assetservercachev3 30 | !Library/expandedItems 31 | !Library/guidmapper 32 | !Library/unity default resources 33 | !Library/unity editor resources 34 | !Library/metadata/ 35 | -------------------------------------------------------------------------------- /Assembly-CSharp-Editor-vs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp-Editor 13 | v3.5 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | Temp\bin\Debug\ 21 | DEBUG;TRACE;UNITY_3_4_2;UNITY_3_4;UNITY_EDITOR;ENABLE_PROFILER;UNITY_STANDALONE_OSX;ENABLE_GENERICS;ENABLE_DUCK_TYPING;ENABLE_TERRAIN;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CLOTH;ENABLE_WWW 22 | prompt 23 | 4 24 | 0169 25 | 26 | 27 | pdbonly 28 | true 29 | Temp\bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 0169 34 | 35 | 36 | 37 | 38 | 39 | 40 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 41 | 42 | 43 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6} 53 | Assembly-CSharp-vs 54 | 55 | 56 | 57 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Assembly-CSharp-Editor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp-Editor 13 | v3.5 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | Temp\bin\Debug\ 21 | DEBUG;TRACE;UNITY_3_4_2;UNITY_3_4;UNITY_EDITOR;ENABLE_PROFILER;UNITY_STANDALONE_OSX;ENABLE_GENERICS;ENABLE_DUCK_TYPING;ENABLE_TERRAIN;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CLOTH;ENABLE_WWW 22 | prompt 23 | 4 24 | 0169 25 | 26 | 27 | pdbonly 28 | true 29 | Temp\bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 0169 34 | 35 | 36 | 37 | 38 | 39 | 40 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 41 | 42 | 43 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6} 53 | Assembly-CSharp 54 | 55 | 56 | 57 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Assembly-CSharp-Editor.pidb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Assembly-CSharp-Editor.pidb -------------------------------------------------------------------------------- /Assembly-CSharp-vs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp 13 | v3.5 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | Temp\bin\Debug\ 21 | DEBUG;TRACE;UNITY_3_4_2;UNITY_3_4;UNITY_EDITOR;ENABLE_PROFILER;UNITY_STANDALONE_OSX;ENABLE_GENERICS;ENABLE_DUCK_TYPING;ENABLE_TERRAIN;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CLOTH;ENABLE_WWW 22 | prompt 23 | 4 24 | 0169 25 | 26 | 27 | pdbonly 28 | true 29 | Temp\bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 0169 34 | 35 | 36 | 37 | 38 | 39 | 40 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 41 | 42 | 43 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Assembly-CSharp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.21022 7 | 2.0 8 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6} 9 | Library 10 | Properties 11 | 12 | Assembly-CSharp 13 | v3.5 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | Temp\bin\Debug\ 21 | DEBUG;TRACE;UNITY_3_4_2;UNITY_3_4;UNITY_EDITOR;ENABLE_PROFILER;UNITY_STANDALONE_OSX;ENABLE_GENERICS;ENABLE_DUCK_TYPING;ENABLE_TERRAIN;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CLOTH;ENABLE_WWW 22 | prompt 23 | 4 24 | 0169 25 | 26 | 27 | pdbonly 28 | true 29 | Temp\bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 0169 34 | 35 | 36 | 37 | 38 | 39 | 40 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll 41 | 42 | 43 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Assembly-CSharp.pidb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Assembly-CSharp.pidb -------------------------------------------------------------------------------- /Assets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Assets/.DS_Store -------------------------------------------------------------------------------- /Assets/Editor/MersenneDebugDrawing.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEngine; 4 | using UnityEditor; 5 | 6 | public class MersenneDebugDrawing 7 | { 8 | public static Texture2D aaLineTex = null; 9 | public static Texture2D lineTex = null; 10 | 11 | public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width, bool antiAlias) 12 | { 13 | Color savedColor = GUI.color; 14 | Matrix4x4 savedMatrix = GUI.matrix; 15 | 16 | if (!lineTex) 17 | { 18 | lineTex = new Texture2D(1, 1, TextureFormat.ARGB32, true); 19 | lineTex.SetPixel(0, 1, Color.white); 20 | lineTex.Apply(); 21 | } 22 | if (!aaLineTex) 23 | { 24 | aaLineTex = new Texture2D(1, 3, TextureFormat.ARGB32, true); 25 | aaLineTex.SetPixel(0, 0, new Color(1, 1, 1, 0)); 26 | aaLineTex.SetPixel(0, 1, Color.white); 27 | aaLineTex.SetPixel(0, 2, new Color(1, 1, 1, 0)); 28 | aaLineTex.Apply(); 29 | } 30 | if (antiAlias) width *= 3; 31 | float angle = Vector3.Angle(pointB - pointA, Vector2.right) * (pointA.y <= pointB.y?1:-1); 32 | float m = (pointB - pointA).magnitude; 33 | if (m > 0.01f) 34 | { 35 | Vector3 dz = new Vector3(pointA.x, pointA.y, 0); 36 | 37 | GUI.color = color; 38 | GUI.matrix = translationMatrix(dz) * GUI.matrix; 39 | GUIUtility.ScaleAroundPivot(new Vector2(m, width), new Vector3(-0.5f, 0, 0)); 40 | GUI.matrix = translationMatrix(-dz) * GUI.matrix; 41 | GUIUtility.RotateAroundPivot(angle, Vector2.zero); 42 | GUI.matrix = translationMatrix(dz + new Vector3(width / 2, -m / 2) * Mathf.Sin(angle * Mathf.Deg2Rad)) * GUI.matrix; 43 | 44 | if (!antiAlias) 45 | GUI.DrawTexture(new Rect(0, 0, 1, 1), lineTex); 46 | else 47 | GUI.DrawTexture(new Rect(0, 0, 1, 1), aaLineTex); 48 | } 49 | GUI.matrix = savedMatrix; 50 | GUI.color = savedColor; 51 | } 52 | 53 | private static Matrix4x4 translationMatrix(Vector3 v) 54 | { 55 | return Matrix4x4.TRS(v,Quaternion.identity,Vector3.one); 56 | } 57 | 58 | public static void DrawPoints(ArrayList rlist, MersenneDebugWindow.MersenneWindowOptionsType op, int width, int height) 59 | { 60 | int counter = 0; 61 | 62 | foreach ( object obj in rlist ) 63 | { 64 | counter++; 65 | 66 | // 1. make a Cross around zero 67 | Vector2 pointA = new Vector2(0.0f,-1.0f); 68 | Vector2 pointB = new Vector2(0.0f,1.0f); 69 | 70 | Vector2 pointC = new Vector2(1.0f,0.0f); 71 | Vector2 pointD = new Vector2(-1.0f,0.0f); 72 | 73 | // 2. move the cross into place 74 | 75 | // Y: value 76 | // X: Position 77 | 78 | float myy = 0; // for data representation I use Convert to Single 79 | 80 | switch (op) 81 | { 82 | case MersenneDebugWindow.MersenneWindowOptionsType.INT: 83 | // scale on Int32 MAX VALUE (again is 0 - 1 range) 84 | myy = (Convert.ToSingle(obj) / Int32.MaxValue); 85 | break; 86 | case MersenneDebugWindow.MersenneWindowOptionsType.FLOAT: 87 | myy = Convert.ToSingle(obj); 88 | break; 89 | case MersenneDebugWindow.MersenneWindowOptionsType.DOUBLE: 90 | myy = Convert.ToSingle(obj); 91 | break; 92 | } 93 | 94 | float myposy = myy * height; 95 | float myposx = counter * (Convert.ToSingle(width) / rlist.Count); 96 | 97 | Vector2 myScalingFactor = new Vector2(myposx,myposy); 98 | 99 | Vector2 pointAs = pointA + myScalingFactor; 100 | Vector2 pointBs = pointB + myScalingFactor; 101 | 102 | Vector2 pointCs = pointC + myScalingFactor; 103 | Vector2 pointDs = pointD + myScalingFactor; 104 | 105 | MersenneDebugDrawing.DrawLine(pointAs,pointBs,Color.blue,1.0f,true); 106 | MersenneDebugDrawing.DrawLine(pointCs,pointDs,Color.blue,1.0f,true); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Assets/Editor/MersenneDebugWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Text; 7 | using System.IO; 8 | 9 | public class MersenneDebugWindow : EditorWindow { 10 | 11 | public enum MersenneWindowOptionsType 12 | { 13 | INT = 0, 14 | FLOAT = 1, 15 | DOUBLE = 2 16 | } 17 | 18 | private MersenneTwister mrand; 19 | private int samplig_size = 500; 20 | private float temperature = 5.0f; 21 | private ArrayList randomList; 22 | private int seed = 0; 23 | private MersenneWindowOptionsType op = MersenneWindowOptionsType.FLOAT; 24 | private Boolean normalizeToggle = false; 25 | private String filename = "sampling.txt"; 26 | private String path; 27 | 28 | // Add menu named "MersenneDebugWindow" to the Window menu 29 | [MenuItem ("Window/Mersenne Twister")] 30 | static void Init () 31 | { 32 | MersenneDebugWindow window = (MersenneDebugWindow)EditorWindow.GetWindowWithRect(typeof (MersenneDebugWindow), new Rect(0, 0, 420, 600)); 33 | window.Show(); 34 | } 35 | 36 | void OnGUI() 37 | { 38 | 39 | GUILayout.BeginArea(new Rect(10, 10, 400, 400)); 40 | GUILayout.Box("RANDOM NUMBER DISTRIBUTION", GUILayout.Width(400), GUILayout.Height(400)); 41 | if (randomList != null && randomList.Count > 0) MersenneDebugDrawing.DrawPoints(randomList, op, 400, 400); 42 | GUILayout.EndArea(); 43 | 44 | GUILayout.BeginArea(new Rect(10, 420, 400, 200)); 45 | seed = EditorGUILayout.IntSlider("Seed:",seed,Int32.MinValue,Int32.MaxValue); 46 | op = (MersenneWindowOptionsType) EditorGUILayout.EnumPopup("Type:", op); 47 | samplig_size = EditorGUILayout.IntSlider ("#N", samplig_size, 1, 1000); 48 | normalizeToggle = EditorGUILayout.Toggle("Normalize", normalizeToggle); 49 | 50 | if (normalizeToggle) { 51 | temperature = EditorGUILayout.Slider ("Temp", temperature, 0.0f, 10.0f); 52 | } 53 | 54 | if (GUILayout.Button("Generate Random Numbers")) this.Sample(); 55 | 56 | if (randomList != null && randomList.Count > 0) { 57 | filename = EditorGUILayout.TextField("filename:", filename); 58 | if (GUILayout.Button("Save To File and Open it")) this.Save(); 59 | } 60 | 61 | if (GUILayout.Button("Close Window")) this.Close(); 62 | 63 | GUILayout.EndArea(); 64 | } 65 | 66 | void Sample() 67 | { 68 | Debug.Log("GENERATING RANDOM NUMBERS WITH SEED: " + seed); 69 | mrand = new MersenneTwister(seed); 70 | randomList = new ArrayList(); 71 | for (int i = 0; i < samplig_size; i++) { 72 | 73 | double myval, rn; 74 | 75 | switch (op) 76 | { 77 | case MersenneWindowOptionsType.INT: 78 | rn = mrand.Next(); 79 | break; 80 | 81 | case MersenneWindowOptionsType.FLOAT: 82 | rn = mrand.NextSingle(true); 83 | break; 84 | 85 | case MersenneWindowOptionsType.DOUBLE: 86 | rn = mrand.NextDouble(true); 87 | break; 88 | 89 | default: 90 | rn = mrand.Next(); 91 | break; 92 | } 93 | 94 | if (normalizeToggle) { 95 | myval = UnityNormalDistribution.toNormalDistribution(rn, temperature); 96 | } else { 97 | myval = rn; 98 | } 99 | 100 | randomList.Add(myval); 101 | } 102 | randomList.Sort(); 103 | this.Repaint(); 104 | } 105 | 106 | void Save() 107 | { 108 | path = Application.dataPath + "/" + filename; 109 | FileStream fs = File.Create(path); 110 | foreach ( object obj in randomList ) { 111 | String data = obj + "\n"; 112 | AddText(fs, data); 113 | } 114 | UnityEngine.Object myfile = AssetDatabase.LoadMainAssetAtPath("Assets/" + filename); 115 | AssetDatabase.OpenAsset(myfile); 116 | } 117 | 118 | private static void AddText(FileStream fs, string value) 119 | { 120 | byte[] info = new UTF8Encoding(true).GetBytes(value); 121 | fs.Write(info, 0, info.Length); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Assets/Scenes/SampleRandom.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Assets/Scenes/SampleRandom.unity -------------------------------------------------------------------------------- /Assets/Scripts/UnityMersenneTwister.cs: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Unity MersenneTwister 4 | 5 | Copyright 2011 Davide Rambaldi (davide.rambaldi@gmail.com) 6 | 7 | Adapted from: http://archive.msdn.microsoft.com/MersenneTwister 8 | 9 | and, of course: 10 | 11 | 12 | A C-program for MT19937, with initialization improved 2002/2/10. 13 | Coded by Takuji Nishimura and Makoto Matsumoto. 14 | This is a faster version by taking Shawn Cokus's optimization, 15 | Matthe Bellew's simplification, Isaku Wada's real version. 16 | 17 | Before using, initialize the state by using init_genrand(seed) 18 | or init_by_array(init_key, key_length). 19 | 20 | Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 21 | All rights reserved. 22 | 23 | Redistribution and use in source and binary forms, with or without 24 | modification, are permitted provided that the following conditions 25 | are met: 26 | 27 | 1. Redistributions of source code must retain the above copyright 28 | notice, this list of conditions and the following disclaimer. 29 | 30 | 2. Redistributions in binary form must reproduce the above copyright 31 | notice, this list of conditions and the following disclaimer in the 32 | documentation and/or other materials provided with the distribution. 33 | 34 | 3. The names of its contributors may not be used to endorse or promote 35 | products derived from this software without specific prior written 36 | permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 39 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 40 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 41 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 42 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 43 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 44 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 45 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 46 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 47 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 48 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | 50 | 51 | Any feedback is very welcome. 52 | http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 53 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 54 | */ 55 | 56 | using System; 57 | 58 | 59 | /* 60 | * Generates pseudo-random numbers using the Mersenne Twister algorithm. 61 | * See http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html and 62 | * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html for details on the algorithm. 63 | */ 64 | 65 | public class MersenneTwister : System.Random 66 | { 67 | /// 68 | /// Creates a new pseudo-random number generator with a given seed. 69 | /// 70 | /// A value to use as a seed. 71 | public MersenneTwister (Int32 seed) 72 | { 73 | init ((UInt32)seed); 74 | } 75 | 76 | /// 77 | /// Creates a new pseudo-random number generator with a default seed. 78 | /// 79 | /// 80 | /// new (). 81 | /// is used for the seed. 82 | /// 83 | public MersenneTwister () : this(new Random ().Next ()) /* a default initial seed is used */ 84 | { 85 | } 86 | 87 | /// 88 | /// Creates a pseudo-random number generator initialized with the given array. 89 | /// 90 | /// The array for initializing keys. 91 | public MersenneTwister (Int32[] initKey) 92 | { 93 | if (initKey == null) { 94 | throw new ArgumentNullException ("initKey"); 95 | } 96 | 97 | UInt32[] initArray = new UInt32[initKey.Length]; 98 | 99 | for (int i = 0; i < initKey.Length; ++i) { 100 | initArray[i] = (UInt32)initKey[i]; 101 | } 102 | 103 | init (initArray); 104 | } 105 | 106 | /// 107 | /// Returns the next pseudo-random . 108 | /// 109 | /// A pseudo-random value. 110 | public virtual UInt32 NextUInt32 () 111 | { 112 | return GenerateUInt32 (); 113 | } 114 | 115 | /// 116 | /// Returns the next pseudo-random 117 | /// up to . 118 | /// 119 | /// 120 | /// The maximum value of the pseudo-random number to create. 121 | /// 122 | /// 123 | /// A pseudo-random value which is at most . 124 | /// 125 | public virtual UInt32 NextUInt32 (UInt32 maxValue) 126 | { 127 | return (UInt32)(GenerateUInt32 () / ((Double)UInt32.MaxValue / maxValue)); 128 | } 129 | 130 | /// 131 | /// Returns the next pseudo-random at least 132 | /// and up to . 133 | /// 134 | /// The minimum value of the pseudo-random number to create. 135 | /// The maximum value of the pseudo-random number to create. 136 | /// 137 | /// A pseudo-random value which is at least 138 | /// and at most . 139 | /// 140 | /// 141 | /// If >= . 142 | /// 143 | public virtual UInt32 NextUInt32 (UInt32 minValue, UInt32 maxValue) /* throws ArgumentOutOfRangeException */ 144 | { 145 | if (minValue >= maxValue) { 146 | throw new ArgumentOutOfRangeException (); 147 | } 148 | 149 | return (UInt32)(GenerateUInt32 () / ((Double)UInt32.MaxValue / (maxValue - minValue)) + minValue); 150 | } 151 | 152 | /// 153 | /// Returns the next pseudo-random . 154 | /// 155 | /// A pseudo-random value. 156 | public override Int32 Next () 157 | { 158 | return Next (Int32.MaxValue); 159 | } 160 | 161 | /// 162 | /// Returns the next pseudo-random up to . 163 | /// 164 | /// The maximum value of the pseudo-random number to create. 165 | /// 166 | /// A pseudo-random value which is at most . 167 | /// 168 | /// 169 | /// When < 0. 170 | /// 171 | public override Int32 Next (Int32 maxValue) 172 | { 173 | if (maxValue <= 1) { 174 | if (maxValue < 0) { 175 | throw new ArgumentOutOfRangeException (); 176 | } 177 | 178 | return 0; 179 | } 180 | 181 | return (Int32)(NextDouble () * maxValue); 182 | } 183 | 184 | /// 185 | /// Returns the next pseudo-random 186 | /// at least 187 | /// and up to . 188 | /// 189 | /// The minimum value of the pseudo-random number to create. 190 | /// The maximum value of the pseudo-random number to create. 191 | /// A pseudo-random Int32 value which is at least and at 192 | /// most . 193 | /// 194 | /// If >= . 195 | /// 196 | public override Int32 Next (Int32 minValue, Int32 maxValue) 197 | { 198 | if (maxValue <= minValue) { 199 | throw new ArgumentOutOfRangeException (); 200 | } 201 | 202 | if (maxValue == minValue) { 203 | return minValue; 204 | } 205 | 206 | return Next (maxValue - minValue) + minValue; 207 | } 208 | 209 | /// 210 | /// Fills a buffer with pseudo-random bytes. 211 | /// 212 | /// The buffer to fill. 213 | /// 214 | /// If == . 215 | /// 216 | public override void NextBytes (Byte[] buffer) 217 | { 218 | // [codekaizen: corrected this to check null before checking length.] 219 | if (buffer == null) { 220 | throw new ArgumentNullException (); 221 | } 222 | 223 | Int32 bufLen = buffer.Length; 224 | 225 | for (Int32 idx = 0; idx < bufLen; ++idx) { 226 | buffer[idx] = (Byte)Next (256); 227 | } 228 | } 229 | 230 | /// 231 | /// Returns the next pseudo-random value. 232 | /// 233 | /// A pseudo-random double floating point value. 234 | /// 235 | /// 236 | /// There are two common ways to create a double floating point using MT19937: 237 | /// using and dividing by 0xFFFFFFFF + 1, 238 | /// or else generating two double words and shifting the first by 26 bits and 239 | /// adding the second. 240 | /// 241 | /// 242 | /// In a newer measurement of the randomness of MT19937 published in the 243 | /// journal "Monte Carlo Methods and Applications, Vol. 12, No. 5-6, pp. 385 ñ 393 (2006)" 244 | /// entitled "A Repetition Test for Pseudo-Random Number Generators", 245 | /// it was found that the 32-bit version of generating a double fails at the 95% 246 | /// confidence level when measuring for expected repetitions of a particular 247 | /// number in a sequence of numbers generated by the algorithm. 248 | /// 249 | /// 250 | /// Due to this, the 53-bit method is implemented here and the 32-bit method 251 | /// of generating a double is not. If, for some reason, 252 | /// the 32-bit method is needed, it can be generated by the following: 253 | /// 254 | /// (Double)NextUInt32() / ((UInt64)UInt32.MaxValue + 1); 255 | /// 256 | /// 257 | /// 258 | public override Double NextDouble () 259 | { 260 | return compute53BitRandom (0, InverseOnePlus53BitsOf1s); 261 | } 262 | 263 | /// 264 | /// Returns a pseudo-random number greater than or equal to zero, and 265 | /// either strictly less than one, or less than or equal to one, 266 | /// depending on the value of the given parameter. 267 | /// 268 | /// 269 | /// If , the pseudo-random number returned will be 270 | /// less than or equal to one; otherwise, the pseudo-random number returned will 271 | /// be strictly less than one. 272 | /// 273 | /// 274 | /// If is , 275 | /// this method returns a double-precision pseudo-random number greater than 276 | /// or equal to zero, and less than or equal to one. 277 | /// If is , this method 278 | /// returns a double-precision pseudo-random number greater than or equal to zero and 279 | /// strictly less than one. 280 | /// 281 | public Double NextDouble (Boolean includeOne) 282 | { 283 | return includeOne ? compute53BitRandom (0, Inverse53BitsOf1s) : NextDouble (); 284 | } 285 | 286 | /// 287 | /// Returns a pseudo-random number greater than 0.0 and less than 1.0. 288 | /// 289 | /// A pseudo-random number greater than 0.0 and less than 1.0. 290 | public Double NextDoublePositive () 291 | { 292 | return compute53BitRandom (0.5, Inverse53BitsOf1s); 293 | } 294 | 295 | /// 296 | /// Returns a pseudo-random number between 0.0 and 1.0. 297 | /// 298 | /// 299 | /// A single-precision floating point number greater than or equal to 0.0, 300 | /// and less than 1.0. 301 | /// 302 | public Single NextSingle () 303 | { 304 | return (Single)NextDouble (); 305 | } 306 | 307 | /// 308 | /// Returns a pseudo-random number greater than or equal to zero, and either strictly 309 | /// less than one, or less than or equal to one, depending on the value of the 310 | /// given boolean parameter. 311 | /// 312 | /// 313 | /// If , the pseudo-random number returned will be 314 | /// less than or equal to one; otherwise, the pseudo-random number returned will 315 | /// be strictly less than one. 316 | /// 317 | /// 318 | /// If is , this method returns a 319 | /// single-precision pseudo-random number greater than or equal to zero, and less 320 | /// than or equal to one. If is , 321 | /// this method returns a single-precision pseudo-random number greater than or equal to zero and 322 | /// strictly less than one. 323 | /// 324 | public Single NextSingle (Boolean includeOne) 325 | { 326 | return (Single)NextDouble (includeOne); 327 | } 328 | 329 | /// 330 | /// Returns a pseudo-random number greater than 0.0 and less than 1.0. 331 | /// 332 | /// A pseudo-random number greater than 0.0 and less than 1.0. 333 | public Single NextSinglePositive () 334 | { 335 | return (Single)NextDoublePositive (); 336 | } 337 | 338 | /// 339 | /// Generates a new pseudo-random . 340 | /// 341 | /// A pseudo-random . 342 | protected UInt32 GenerateUInt32 () 343 | { 344 | UInt32 y; 345 | 346 | /* _mag01[x] = x * MatrixA for x=0,1 */ 347 | if (_mti >= N) /* generate N words at one time */ { 348 | Int16 kk = 0; 349 | 350 | for (; kk < N - M; ++kk) { 351 | y = (_mt[kk] & UpperMask) | (_mt[kk + 1] & LowerMask); 352 | _mt[kk] = _mt[kk + M] ^ (y >> 1) ^ _mag01[y & 0x1]; 353 | } 354 | 355 | for (; kk < N - 1; ++kk) { 356 | y = (_mt[kk] & UpperMask) | (_mt[kk + 1] & LowerMask); 357 | _mt[kk] = _mt[kk + (M - N)] ^ (y >> 1) ^ _mag01[y & 0x1]; 358 | } 359 | 360 | y = (_mt[N - 1] & UpperMask) | (_mt[0] & LowerMask); 361 | _mt[N - 1] = _mt[M - 1] ^ (y >> 1) ^ _mag01[y & 0x1]; 362 | 363 | _mti = 0; 364 | } 365 | 366 | y = _mt[_mti++]; 367 | y ^= temperingShiftU (y); 368 | y ^= temperingShiftS (y) & TemperingMaskB; 369 | y ^= temperingShiftT (y) & TemperingMaskC; 370 | y ^= temperingShiftL (y); 371 | 372 | return y; 373 | } 374 | 375 | /* Period parameters */ 376 | private const Int32 N = 624; 377 | private const Int32 M = 397; 378 | private const UInt32 MatrixA = 0x9908b0df; 379 | /* constant vector a */ private const UInt32 UpperMask = 0x80000000; 380 | /* most significant w-r bits */ private const UInt32 LowerMask = 0x7fffffff; 381 | /* least significant r bits */ 382 | /* Tempering parameters */ 383 | private const UInt32 TemperingMaskB = 0x9d2c5680; 384 | private const UInt32 TemperingMaskC = 0xefc60000; 385 | 386 | private static UInt32 temperingShiftU (UInt32 y) 387 | { 388 | return (y >> 11); 389 | } 390 | 391 | private static UInt32 temperingShiftS (UInt32 y) 392 | { 393 | return (y << 7); 394 | } 395 | 396 | private static UInt32 temperingShiftT (UInt32 y) 397 | { 398 | return (y << 15); 399 | } 400 | 401 | private static UInt32 temperingShiftL (UInt32 y) 402 | { 403 | return (y >> 18); 404 | } 405 | 406 | private readonly UInt32[] _mt = new UInt32[N]; 407 | /* the array for the state vector */ private Int16 _mti; 408 | 409 | private static readonly UInt32[] _mag01 = { 0x0, MatrixA }; 410 | 411 | private void init (UInt32 seed) 412 | { 413 | _mt[0] = seed & 0xffffffffu; 414 | 415 | for (_mti = 1; _mti < N; _mti++) { 416 | _mt[_mti] = (uint)(1812433253u * (_mt[_mti - 1] ^ (_mt[_mti - 1] >> 30)) + _mti); 417 | // See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. 418 | // In the previous versions, MSBs of the seed affect 419 | // only MSBs of the array _mt[]. 420 | // 2002/01/09 modified by Makoto Matsumoto 421 | _mt[_mti] &= 0xffffffffu; 422 | // for >32 bit machines 423 | } 424 | } 425 | 426 | private void init (UInt32[] key) 427 | { 428 | Int32 i, j, k; 429 | init (19650218u); 430 | 431 | Int32 keyLength = key.Length; 432 | i = 1; 433 | j = 0; 434 | k = (N > keyLength ? N : keyLength); 435 | 436 | for (; k > 0; k--) { 437 | _mt[i] = (uint)((_mt[i] ^ ((_mt[i - 1] ^ (_mt[i - 1] >> 30)) * 1664525u)) + key[j] + j); 438 | /* non linear */ _mt[i] &= 0xffffffffu; 439 | // for WORDSIZE > 32 machines 440 | i++; 441 | j++; 442 | if (i >= N) { 443 | _mt[0] = _mt[N - 1]; 444 | i = 1; 445 | } 446 | if (j >= keyLength) 447 | j = 0; 448 | } 449 | 450 | for (k = N - 1; k > 0; k--) { 451 | _mt[i] = (uint)((_mt[i] ^ ((_mt[i - 1] ^ (_mt[i - 1] >> 30)) * 1566083941u)) - i); 452 | /* non linear */ _mt[i] &= 0xffffffffu; 453 | // for WORDSIZE > 32 machines 454 | i++; 455 | 456 | if (i < N) { 457 | continue; 458 | } 459 | 460 | _mt[0] = _mt[N - 1]; 461 | i = 1; 462 | } 463 | 464 | _mt[0] = 0x80000000u; 465 | // MSB is 1; assuring non-zero initial array 466 | } 467 | 468 | 469 | // 9007199254740991.0 is the maximum double value which the 53 significand 470 | // can hold when the exponent is 0. 471 | private const Double FiftyThreeBitsOf1s = 9007199254740991.0; 472 | // Multiply by inverse to (vainly?) try to avoid a division. 473 | private const Double Inverse53BitsOf1s = 1.0 / FiftyThreeBitsOf1s; 474 | private const Double OnePlus53BitsOf1s = FiftyThreeBitsOf1s + 1; 475 | private const Double InverseOnePlus53BitsOf1s = 1.0 / OnePlus53BitsOf1s; 476 | 477 | private Double compute53BitRandom (Double translate, Double scale) 478 | { 479 | // get 27 pseudo-random bits 480 | UInt64 a = (UInt64)GenerateUInt32 () >> 5; 481 | // get 26 pseudo-random bits 482 | UInt64 b = (UInt64)GenerateUInt32 () >> 6; 483 | 484 | // shift the 27 pseudo-random bits (a) over by 26 bits (* 67108864.0) and 485 | // add another pseudo-random 26 bits (+ b). 486 | return ((a * 67108864.0 + b) + translate) * scale; 487 | 488 | // What about the following instead of the above? Is the multiply better? 489 | // Why? (Is it the FMUL instruction? Does this count in .Net? Will the JITter notice?) 490 | //return BitConverter.Int64BitsToDouble((a << 26) + b)); 491 | } 492 | } 493 | -------------------------------------------------------------------------------- /Assets/Scripts/UnityNormalDistribution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class UnityNormalDistribution 4 | { 5 | public static double stdnormal_cdf(double u) 6 | { 7 | const double m_1_sqrtpi = 0.564189583547756286948; 8 | double msqrt2 = 1.41421356237309504880; 9 | double z, y; 10 | 11 | double[] a = new double [] { 12 | 1.161110663653770e-002, 13 | 3.951404679838207e-001, 14 | 2.846603853776254e+001, 15 | 1.887426188426510e+002, 16 | 3.209377589138469e+003 17 | }; 18 | 19 | double[] b = new double [] { 20 | 1.767766952966369e-001, 21 | 8.344316438579620e+000, 22 | 1.725514762600375e+002, 23 | 1.813893686502485e+003, 24 | 8.044716608901563e+003 25 | }; 26 | 27 | double[] c = new double [] { 28 | 2.15311535474403846e-8, 29 | 5.64188496988670089e-1, 30 | 8.88314979438837594e00, 31 | 6.61191906371416295e01, 32 | 2.98635138197400131e02, 33 | 8.81952221241769090e02, 34 | 1.71204761263407058e03, 35 | 2.05107837782607147e03, 36 | 1.23033935479799725E03 37 | }; 38 | 39 | double[] d = new double [] { 40 | 1.00000000000000000e00, 41 | 1.57449261107098347e01, 42 | 1.17693950891312499e02, 43 | 5.37181101862009858e02, 44 | 1.62138957456669019e03, 45 | 3.29079923573345963e03, 46 | 4.36261909014324716e03, 47 | 3.43936767414372164e03, 48 | 1.23033935480374942e03 49 | }; 50 | 51 | double[] p = new double [] { 52 | 1.63153871373020978e-2, 53 | 3.05326634961232344e-1, 54 | 3.60344899949804439e-1, 55 | 1.25781726111229246e-1, 56 | 1.60837851487422766e-2, 57 | 6.58749161529837803e-4 58 | }; 59 | 60 | double[] q = new double [] { 61 | 1.00000000000000000e00, 62 | 2.56852019228982242e00, 63 | 1.87295284992346047e00, 64 | 5.27905102951428412e-1, 65 | 6.05183413124413191e-2, 66 | 2.33520497626869185e-3 67 | }; 68 | 69 | if (Double.IsNaN(u)) { 70 | return(Double.NaN); 71 | } 72 | 73 | if(Double.IsInfinity(u)) { 74 | return (u < 0 ? 0.0 : 1.0); 75 | } 76 | 77 | y = Math.Abs(u); 78 | 79 | if (y <= 0.46875*msqrt2) { 80 | /* evaluate erf() for |u| <= sqrt(2)*0.46875 */ 81 | z = y*y; 82 | y = u*((((a[0]*z+a[1])*z+a[2])*z+a[3])*z+a[4])/((((b[0]*z+b[1])*z+b[2])*z+b[3])*z+b[4]); 83 | return 0.5+y; 84 | } 85 | 86 | z = Math.Exp(-y*y/2)/2; 87 | if (y <= 4.0) { 88 | /* evaluate erfc() for sqrt(2)*0.46875 <= |u| <= sqrt(2)*4.0 */ 89 | y = y/msqrt2; 90 | y = ((((((((c[0]*y+c[1])*y+c[2])*y+c[3])*y+c[4])*y+c[5])*y+c[6])*y+c[7])*y+c[8]) 91 | / ((((((((d[0]*y+d[1])*y+d[2])*y+d[3])*y+d[4])*y+d[5])*y+d[6])*y+d[7])*y+d[8]); 92 | y = z*y; 93 | } else { 94 | /* evaluate erfc() for |u| > sqrt(2)*4.0 */ 95 | z = z*msqrt2/y; 96 | y = 2/(y*y); 97 | y = y*(((((p[0]*y+p[1])*y+p[2])*y+p[3])*y+p[4])*y+p[5]) 98 | /(((((q[0]*y+q[1])*y+q[2])*y+q[3])*y+q[4])*y+q[5]); 99 | y = z*(m_1_sqrtpi-y); 100 | } 101 | 102 | return (u < 0.0 ? y : 1-y); 103 | 104 | } 105 | 106 | public static double stdnormal_inv(double p) 107 | { 108 | const double m_sqrt2pi = 2.50662827463100; 109 | double[] a = new double [] { 110 | -3.969683028665376e+01, 2.209460984245205e+02, 111 | -2.759285104469687e+02, 1.383577518672690e+02, 112 | -3.066479806614716e+01, 2.506628277459239e+00 113 | }; 114 | 115 | double[] b = new double [] { 116 | -5.447609879822406e+01, 1.615858368580409e+02, 117 | -1.556989798598866e+02, 6.680131188771972e+01, 118 | -1.328068155288572e+01 119 | }; 120 | 121 | double[] c = new double [] { 122 | -7.784894002430293e-03, -3.223964580411365e-01, 123 | -2.400758277161838e+00, -2.549732539343734e+00, 124 | 4.374664141464968e+00, 2.938163982698783e+00 125 | }; 126 | 127 | double[] d = new double [] { 128 | 7.784695709041462e-03, 3.224671290700398e-01, 129 | 2.445134137142996e+00, 3.754408661907416e+00 130 | }; 131 | 132 | double q, t, u; 133 | 134 | if (Double.IsNaN(p) || p > 1.0 || p < 0.0) 135 | { 136 | return(Double.NaN); 137 | } 138 | if (p == 0.0) 139 | { 140 | return Double.NegativeInfinity; 141 | } 142 | if (p == 1.0) 143 | { 144 | return Double.PositiveInfinity; 145 | } 146 | 147 | q = (p < (1-p)) ? p : (1-p); 148 | 149 | if (q > 0.02425) { 150 | /* Rational approximation for central region. */ 151 | u = q-0.5; 152 | t = u*u; 153 | u = u*(((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4])*t+a[5]) 154 | /(((((b[0]*t+b[1])*t+b[2])*t+b[3])*t+b[4])*t+1); 155 | } else { 156 | /* Rational approximation for tail region. */ 157 | t = Math.Sqrt(-2*Math.Log(q)); 158 | u = (((((c[0]*t+c[1])*t+c[2])*t+c[3])*t+c[4])*t+c[5]) 159 | /((((d[0]*t+d[1])*t+d[2])*t+d[3])*t+1); 160 | } 161 | 162 | /* The relative error of the approximation has absolute value less 163 | than 1.15e-9. One iteration of Halley's rational method (third 164 | order) gives full machine precision... */ 165 | 166 | t = stdnormal_cdf(u)-q; /* error */ 167 | t = t*m_sqrt2pi*Math.Exp(u*u/2); /* f(u)/df(u) */ 168 | u = u-t/(1+u*t/2); /* Halley's method */ 169 | 170 | return (p > 0.5 ? -u : u); 171 | } 172 | 173 | public static double toNormalDistribution(double rn, float temperature) 174 | { 175 | // Trasformiamo questo numero in una distribuzione normale (CDF inversa, nota anche come Gaussiana, vedi http://en.wikipedia.org/wiki/Normal_distribution) 176 | // facendo l'inversa della cumulative density function su una distribuzione uniforme [0,1] otteniamo una distribuzione normale (-inf,+inf) centrata a zero 177 | // e con deviazione standard 1 178 | double localVal = stdnormal_inv(rn); 179 | 180 | // A questo punto passiamo attraverso una funzione sigmoide (o curva logistica) con Lateratura 5 181 | // Questo ci riporta a un campo (0,1), il valore 5 fa si che circa il 90% dei valori restituiti sia tra 0.45 e 0.55, aumentandolo 182 | // la distribuzione si stringe (piu' valori vicini a 0.5), abbassandolo si allarga, ma a differenza di una gaussiana in ogni caso 183 | // il valore restituito e' tra zero e uno. 184 | localVal = localVal / temperature; 185 | localVal = 1.0 / (1.0 + Math.Exp(-localVal)); 186 | return(localVal); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /Library/AssetImportState: -------------------------------------------------------------------------------- 1 | 2;0 -------------------------------------------------------------------------------- /Library/AssetVersioning.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/AssetVersioning.db -------------------------------------------------------------------------------- /Library/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/AudioManager.asset -------------------------------------------------------------------------------- /Library/BuildPlayer.prefs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/BuildPlayer.prefs -------------------------------------------------------------------------------- /Library/BuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/BuildSettings.asset -------------------------------------------------------------------------------- /Library/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/DynamicsManager.asset -------------------------------------------------------------------------------- /Library/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Library/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/EditorSettings.asset -------------------------------------------------------------------------------- /Library/EditorUserBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/EditorUserBuildSettings.asset -------------------------------------------------------------------------------- /Library/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/InputManager.asset -------------------------------------------------------------------------------- /Library/InspectorExpandedItems.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/InspectorExpandedItems.asset -------------------------------------------------------------------------------- /Library/MonoManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/MonoManager.asset -------------------------------------------------------------------------------- /Library/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/NetworkManager.asset -------------------------------------------------------------------------------- /Library/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/ProjectSettings.asset -------------------------------------------------------------------------------- /Library/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/QualitySettings.asset -------------------------------------------------------------------------------- /Library/ScriptMapper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/ScriptMapper -------------------------------------------------------------------------------- /Library/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/TagManager.asset -------------------------------------------------------------------------------- /Library/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/TimeManager.asset -------------------------------------------------------------------------------- /Library/assetservercachev3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/assetservercachev3 -------------------------------------------------------------------------------- /Library/expandedItems: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/expandedItems -------------------------------------------------------------------------------- /Library/guidmapper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/guidmapper -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000001000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000001000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000002000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000002000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000003000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000003000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000004000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000004000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000005000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000005000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000006000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000006000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000007000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000007000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000008000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000008000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/00000000000000009000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/00000000000000009000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/0000000000000000a000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/0000000000000000a000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/0000000000000000b000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/0000000000000000b000000000000000 -------------------------------------------------------------------------------- /Library/metadata/00/0000000000000000c000000000000000: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/00/0000000000000000c000000000000000 -------------------------------------------------------------------------------- /Library/metadata/32/3249ce278b3bc4e34bc61a3b216de49b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/32/3249ce278b3bc4e34bc61a3b216de49b -------------------------------------------------------------------------------- /Library/metadata/5a/5a5af9208f20d47c4bd06c20f668439e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/5a/5a5af9208f20d47c4bd06c20f668439e -------------------------------------------------------------------------------- /Library/metadata/65/65814e72818854fd2a54f1facb448af0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/65/65814e72818854fd2a54f1facb448af0 -------------------------------------------------------------------------------- /Library/metadata/78/78cde2e81b5e348a4acb0f80a4f64bb1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/78/78cde2e81b5e348a4acb0f80a4f64bb1 -------------------------------------------------------------------------------- /Library/metadata/c1/c14325ecf63c2a54f9069d125181eae1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/c1/c14325ecf63c2a54f9069d125181eae1 -------------------------------------------------------------------------------- /Library/metadata/d4/d4a86cbe20e284ea8a7d8b61831e652e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/d4/d4a86cbe20e284ea8a7d8b61831e652e -------------------------------------------------------------------------------- /Library/metadata/dd/dd1258601dba44313a1a7a0de637cee6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/dd/dd1258601dba44313a1a7a0de637cee6 -------------------------------------------------------------------------------- /Library/metadata/e2/e24b40a12e08947498ae05d50922f0c3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Library/metadata/e2/e24b40a12e08947498ae05d50922f0c3 -------------------------------------------------------------------------------- /Package/TwisterAndNormalize.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tucano/UnityMersenneTwister/f1144c14e87ebf93fa3d9022da21ea0ed0183260/Package/TwisterAndNormalize.unitypackage -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | == RANDOM NUMBERS IN UNITY C# scripting == 2 | 3 | * Mersenne Twister 4 | * Normalization 5 | 6 | 7 | == TODO == 8 | 9 | * Better interface (EditorWindow) and Interactions with Scene 10 | * Better data representation in EditorInterface 11 | * More normalization methods 12 | 13 | Feel free to contribute and add new features. 14 | 15 | == FILES == 16 | 17 | This directory is a Unity Project with .gitignore ignoring the common files for the Unity FREE Version 18 | 19 | see: http://forum.unity3d.com/threads/69609-Source-Control-w-Free-Unity-ignore-files-(Git-SVN-CVS) 20 | 21 | - If you want to contribute clone the repo, modify and ask for a pull request 22 | 23 | - If you just want to use it, you can take the file Package/TwisterAndNormalize.unitypackage . 24 | 25 | I started playing with the Unity framework and I came out with this first small library that may be is useful for someone else. 26 | 27 | I ported into Unity the Mersenne-Twister pseudorandom number generator and a function to convert the random sets of data in a Normal Distribution. 28 | 29 | Still "work in progress" but I want to post the code to see if anyone is interested in help me with critics and suggestions. 30 | 31 | 32 | The unity package contains: 33 | 34 | Scripts 35 | 36 | - UnityMersenneTwister.cs: Mersenne Twister Pseudo Random generator 37 | - UnityNormalDistribution.cs: Functions to convert the random number using a normal cdf 38 | 39 | Editor/Scripts 40 | 41 | - MersenneDebugWindow.cs : This script create a window to test the random numbers and the normalization, and to write a random numbers to a file (for further analysis with a statistics package) 42 | - MersenneDebugDrawing.cs : This script is used to draw a simple scatterplot of the random generated data 43 | 44 | In syntesis: we generate normal distributed random numbers that can be useful in some applications inside a game (AI beaviour, terrain generation, etc....). If you need a Gaussian noise, may be this package is for you! 45 | 46 | 47 | -------------------------------------------------------------------------------- /TestTwister-csharp.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | 4 | Project("{57D407BF-141F-94F6-E788-C8212021D146}") = "TestTwister", "Assembly-CSharp-vs.csproj", "{C6CBC76F-A682-C57F-729E-4B2D845A91C6}" 5 | EndProject 6 | Project("{57D407BF-141F-94F6-E788-C8212021D146}") = "TestTwister", "Assembly-CSharp-Editor-vs.csproj", "{B9DFF45A-4CC5-60AB-9637-13CE43F1058F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /TestTwister.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | 4 | Project("{57D407BF-141F-94F6-E788-C8212021D146}") = "TestTwister", "Assembly-CSharp.csproj", "{C6CBC76F-A682-C57F-729E-4B2D845A91C6}" 5 | EndProject 6 | Project("{57D407BF-141F-94F6-E788-C8212021D146}") = "TestTwister", "Assembly-CSharp-Editor.csproj", "{B9DFF45A-4CC5-60AB-9637-13CE43F1058F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C6CBC76F-A682-C57F-729E-4B2D845A91C6}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {B9DFF45A-4CC5-60AB-9637-13CE43F1058F}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /TestTwister.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------