Home > Mobile >  C# Form | A code that generates a random 0 and 1 32 times
C# Form | A code that generates a random 0 and 1 32 times

Time:11-15

A code that randomly generates 1 and 0 when the button is clicked

When the button is clicked, 1 and 0 should be written randomly 32 times.

Example: 10110010101100101011001010110111

CodePudding user response:

Hi I recommend starting with pseudocode. After that, you can start with "c# How to generate a random number" and so on.. Take a look at loops and there you go.

Have fun with starting programming :)

CodePudding user response:

    string binary = null;
    Random rand = new Random();
    for (int i = 0; i < 32; i  )
    {
        if (rand.Next(2)==1){
            binary ="1";
        }
        else
            binary ="0";
    }
    
  •  Tags:  
  • c#
  • Related