- Home /
How to make sure a sequence is COMPLETELY random?
I have a maze in which a pressure plate randomly selects a wall from around it, if it exists remove it, if not try again. Once successful, it destroys the pressure plate so it cant be triggered again (if it finds no walls, it infinite loops...)
All I'm trying to do is make sure that the Random
I'm using is actually random. Right no I have it using Random.seed = System.Environment.TickCount
and I'm relying on the fact that the game is not optimized and is laggy, to wait for the script to initalize in a different number of ticks. Right now, it seems random, but it is only actually 3-4 real paths, that are selected in a random order. I looked in the Random.seed
documentation, and it says something about setting it to the system date and time, and I was wondering how to do that (it seems like it'd be more random). When I use the Date()
to set the seed, apparently you can't change a function to an int
.
Current Code:
var wall1:GameObject;
var wall2:GameObject;
var wall3:GameObject;
var wall4:GameObject;
var pressurePad:GameObject;
public var randomWall:int;
public var canRun:boolean = true;
public var platesTriggered:float;
public var wallsRemoved:float;
public var clip:AudioClip;
function Start () {
Random.seed = System.Environment.TickCount;
}
function OnTriggerEnter (other:Collider) {
canRun = true;
platesTriggered = platesTriggered + 1;
RemoveDoor();
}
function RemoveDoor() {
if (canRun == true) {
randomWall = Random.Range(0,5); //random int between 1-4
print(randomWall);
if (wall1 != null && randomWall == 1 && wall1.activeInHierarchy == true) { //wall 1 selected
wall1.SetActive(false);
wallsRemoved = wallsRemoved + 1;
AudioSource.PlayClipAtPoint(clip, wall1.transform.position);
Destroy(pressurePad);
canRun = false;
}
else if (wall2 != null && randomWall == 2 && wall2.activeInHierarchy == true) { //wall 2 selected
wall2.SetActive(false);
wallsRemoved = wallsRemoved + 1;
AudioSource.PlayClipAtPoint(clip, wall2.transform.position);
Destroy(pressurePad);
canRun = false;
}
else if (wall3 != null && randomWall == 3 && wall3.activeInHierarchy == true) { //wall 3 selected
wall3.SetActive(false);
wallsRemoved = wallsRemoved + 1;
AudioSource.PlayClipAtPoint(clip, wall3.transform.position);
Destroy(pressurePad);
canRun = false;
}
else if (wall4 != null && randomWall == 4 && wall4.activeInHierarchy == true) { //wall 4 selected
wall4.SetActive(false);
wallsRemoved = wallsRemoved + 1;
AudioSource.PlayClipAtPoint(clip, wall4.transform.position);
Destroy(pressurePad);
canRun = false;
}
else {
RemoveDoor();
}
}
}
I'd be cool if you could help!
Unity automatically initializes the seed using the system clock. That's pretty standard practice.
In other words, leave out the Random.seed part. Only use Random.seed if you want repeatable results.
Your answer
Follow this Question
Related Questions
Random.seed Repeating 2 Answers
Create number of enemies when one is deid 1 Answer
¿how to take all values from an array without order? 2 Answers
Using arrays to randomly select an object 0 Answers
Random Range Seems... Unrandom 1 Answer