Skip to content

Instantly share code, notes, and snippets.

@mandarinx
Created November 21, 2016 20:22
Show Gist options
  • Save mandarinx/c38b52e9f89ca4a62f93d0e3455aeb5c to your computer and use it in GitHub Desktop.
Save mandarinx/c38b52e9f89ca4a62f93d0e3455aeb5c to your computer and use it in GitHub Desktop.
Random distribution in Unity
using UnityEngine;
public class Rnd : MonoBehaviour {
private float[] results;
private float max;
void Awake() {
max = 0f;
results = new float[1000];
for (int i=0; i<(1000*100); i++) {
int r = Random.Range(0, 1000);
results[r]++;
if (results[r] > max) {
max = results[r];
}
}
for (int i=0; i<results.Length; i++) {
results[i] = results[i] / max;
}
}
void Start() {
for (int i=0; i<results.Length; i++) {
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad);
Vector3 scale = new Vector3(.1f, results[i], 1f);
go.transform.localScale = scale;
Vector3 pos = scale * 0.5f + Vector3.right * i * .1f;
go.transform.localPosition = pos;
}
Camera.main.transform.position = Vector3.right * (1000 / 2) * .1f - Vector3.forward * 25f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment