โœ… Random character generator

Hello, as a beginner, I am currently working on making a simple lottery simulator. However, I didn't know how to generate a sequence of 8 letters and numbers. Naturally, I searched it up and I got the answer. But copying chunks of code wouldn't help me learn and I can't seem to wrap my head around how this works. I understand the variables, but I can't just seem to understand what the variable i does and why i = 0. Would anyone be kind enough to explain the for statement and what each argument does. Thank you so much ๐Ÿ™
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var stringChars = new char[8];
var randomNumber = new Random();

for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[randomNumber.Next(chars.Length)] ;
}

var finalString = new String(stringChars);

Console.WriteLine(finalString);
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var stringChars = new char[8];
var randomNumber = new Random();

for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[randomNumber.Next(chars.Length)] ;
}

var finalString = new String(stringChars);

Console.WriteLine(finalString);
6 Replies
cookiesaredelicious
cookiesaredeliciousOPโ€ข2y ago
After messing around with the values and variables I now know what i means and how the loop works. However, another problem came to mind. Is there a way to return to a previous line of code? for example when I press something like space, it returns to before the sequence is generated and it would give me another code without having to restart the entire program
cause77
cause77โ€ข2y ago
GitHub
PwGen-CSharp/PwGen.cs at master ยท MCausc78/PwGen-CSharp
A password generator written in C#. Contribute to MCausc78/PwGen-CSharp development by creating an account on GitHub.
cause77
cause77โ€ข2y ago
GitHub
PwGen-CSharp/Flag.cs at master ยท MCausc78/PwGen-CSharp
A password generator written in C#. Contribute to MCausc78/PwGen-CSharp development by creating an account on GitHub.
deem
deemโ€ข2y ago
Search up these keywords: Goto, return, continue, break Although using goto isn't considered proffessional
cookiesaredelicious
cookiesaredeliciousOPโ€ข2y ago
i will look into them tysm ๐Ÿ™ ๐Ÿ‘
Accord
Accordโ€ข2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server