using UnityEngine; using System.Collections; public class Gaussian : MonoBehaviour { public int seed = 61829450; double sum = 0; long r = 0; // Use this for initialization void Start() { } // Update is called once per frame void Update() { if (Time.frameCount % 7== 0) { // seed = 61829450; sum = 0; for (int i = 0; i < 3; i++) { long holdseed = seed; seed ^= seed << 13; seed ^= seed >> 17; seed ^= seed << 5; r = holdseed + seed; sum += (double)r * (1.0 / 0x7FFFFFFFFFFFFFFF); } print( sum); //returns [-3.0, 3.0] at (66.7%, 95.8%, 100%) } } }
如果想要产生的结果更真实,就是用高斯分布随机。如果为了让玩家更开心,可以对产生的随机数进行过滤。
------by wolf96 http://blog.csdn.net/wolf96
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wolf96/article/details/48242853