I’m using this in my game to generate a 4 digit code that the player needs to enter to escape the room.

In my game the 4 digits you need to find are hidden in different locations around the room.

Using the random.range, I’ve done it so that rather than digit 1 of the code being at location 1, the location is also randomised so that digit any of the 4 digits can appear at any of the 4 locations. Although basic, it adds a tiny bit of replayability!

If anyone’s interested, here is how I did that bit of code…

```
void codemaker () {
code[0]=Random.Range(0,10);
code[1]=Random.Range(0,10);
code[2]=Random.Range(0,10);
code[3]=Random.Range(0,10);
a = Random.Range(0,4);
b = Random.Range(0,4);
while (b==a) {
b=Random.Range(0,4);
}
c = Random.Range (0,4);
while (c==b || c==a) {
c=Random.Range (0,4);
}
if ((a==0 || b==0 || c==0) && (a==1 || b==1 || c==1) && (a==2 || b==2 || c==2)) {d=3;}
else if ((a==1 || b==1 || c==1) && (a==2 || b==2 || c==2) && (a==3 || b==3 || c==3)) {d=0;}
else if ((a==2 || b==2 || c==2) && (a==3 || b==3 || c==3) && (a==0 || b==0 || c==0)) {d=1;}
else if ((a==3 || b==3 || c==3) && (a==0 || b==0 || c==0) && (a==1 || b==1 || c==1)) {d=2;}
if (a==0) {nwallstart="";nwallend=" * * *\n\n";}
else if (a==1) {nwallstart="* ";nwallend=" * *\n\n";}
else if (a==2) {nwallstart="* * ";nwallend=" *\n\n";}
else if (a==3) {nwallstart="* * * ";nwallend="\n\n";}
if (b==0) {screencodestart="";screencodeend="XXX\n\n";}
else if (b==1) {screencodestart="X";screencodeend="XX\n\n";}
else if (b==2) {screencodestart="XX";screencodeend="X\n\n";}
else if (b==3) {screencodestart="XXX";screencodeend="\n\n";}
if (c==0) {ceilingstart="1st is ";ceilingend="\n\n";}
else if (c==1) {ceilingstart="2nd is ";ceilingend="\n\n";}
else if (c==2) {ceilingstart="3rd is ";ceilingend="\n\n";}
else if (c==3) {ceilingstart="4th is ";ceilingend="\n\n";}
codemade=1;
return;
}
```