Random and .Length is very helpful

It was very usefull to me, learning how to use random in a password list., also how awesome it is to make the program know how many entry there is in the database with .Length. This is new to me and open a world with many new possibilities. Thanks!

void StartGame() // set screen to Password
{
    CurrentScreen = Screen.Password;
    int index;
    switch (level)
    {
        case 1:
            index = Random.Range(0, level1Passwords.Length);// Pick random password from level1Passwords
            password = level1Passwords[index]; // Use random password
            break;
        case 2:
            index = Random.Range(0, level2Passwords.Length);
            password = level2Passwords[index];
            break;
        case 3:
            index = Random.Range(0, level3Passwords.Length);
            password = level3Passwords[index];
            break;
    }
    Terminal.WriteLine("Please type a password");
}
1 Like

Privacy & Terms