Random.range

Hey all. I got this script off of Unity’s documentation.

function Choose(probs: float[]) {
    var total = 0;
    
    for (elem in probs) {
        total += elem;
    }
    
    var randomPoint = Random.value * total;
    
    for (i = 0; i < probs.Length; i++) {
        if (randomPoint < probs*)*

return i;
else
randomPoint -= probs*;*
}

return probs.Length - 1;
}
I want to apply this to my game so that there are 4 doors. One of the doors, chosen at random, when clicked, kills the player. If there are 4 doors I want once the scene starts the script to pick one of the doors to be the kill door, thus making the game different every time played. So each door has a 20% chance of being the kill door. Then once a kill door is determined, another can’t be found. I’m new to scripting. Is this possible with this script? If so where do I input my percent chance variables within it?
Thanks!

Not sure why u need such complex code to do simple task, here is how I will do it.

public GameObject [] doors;
private GameObject killDoor;

// Call this when init a level.
void RollKillDoor()
{
    killDoor = doors [ Random.Range ( 0, killdoor.Length ) ];
}

// When player choose the door, pass the parameter here.
void OpenDoor ( GameObject choosenDoor )
{
    if ( choosenDoor == killDoor )
    {
        print ( "Game over" );
    }
    else
    {
        print ( "Success!" );
    }
}