mercredi 20 janvier 2021

How to select a random value from a preselected list using booleans to enabled or disabled available values?

Using the random class can I preselect numbers it can only use while just using Booleans?

For Example: Say I want a Random Number Between 0-9 But I want to only select from the numbers 1,4,6, and 8 if say The Booleans Named: "One", "Four", "Six", "Eight" are true.

    bool Zero = false;
    bool One = true;
    bool Two = false;
    bool Three = false;
    bool Four = true;
    bool Five = false;
    bool Six = true;
    bool Seven = false;
    bool Eight = true;
    bool Nine = false;

So It Would Output Something Like This: 18441861684168448418411864816

Is there a way to go about that using the "Random Class" that is below but swap out the values(1, 10) for only the true Booleans above or will I need to use something else? If so what do you recommend?

Random rnd = new Random();
int RandomizedNumber = rnd.Next(1, 10);  // creates a number between 1 and 9

I am using Visual Studios Windows Forms in C#.




Aucun commentaire:

Enregistrer un commentaire