Post: [Source] Random Number Generator
12-14-2011, 02:19 AM #1
Pichu
RIP PICHU.
(adsbygoogle = window.adsbygoogle || []).push({});
Random Number Generator.
UPDATED! ADDED VIDEO TUTORIAL!

How to use:
Select your Maximum and Minimum
Select how many times you want a number generated
Press generate

A list of randomly generated based on how many times you want it to generate will appear in the box on the right, when it is complete you will be prompted with a message box telling you it is completed.

This is great to use when you have to generate more than one random number, EG a raffle on here with 10 winners. Instead of using Random.Org and pressing it 10 times you can just generate all at once.

Difficulty: 1/10

Time taken: 10 minutes

Download to .exe file: You must login or register to view this content.

Video Tutorial: Added 12/23/11


You must login or register to view this content.


Source:

        
Random rnd = new Random();
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
numericUpDown1.Enabled = false;
numericUpDown2.Enabled = false;
numericUpDown3.Enabled = false;
button1.Enabled = false;
int a = Convert.ToInt32(numericUpDown1.Value);
int b = Convert.ToInt32(numericUpDown2.Value);
int c = Convert.ToInt32(numericUpDown3.Value);
for (int counter = 1; counter <= c; counter++)
{
int num = rnd.Next((b - 1), (a + 1));
if (num < 0)
{
num = num * -1;
}
richTextBox1.Text = num + "\n" + richTextBox1.Text;
if (counter == c)
{
button1.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
numericUpDown3.Enabled = true;
MessageBox.Show("Number of generated numbers is " + c, "Completed");
}
}
}


private void checkvalue_Tick(object sender, EventArgs e)
{
if (numericUpDown2.Value >= numericUpDown1.Value)
{
numericUpDown1.Value = numericUpDown2.Value + 1;
}
}
}


As you can see it is a very simple program, to those who are learning hopefully this code teaches you something.
Last edited by Pichu ; 12-23-2011 at 10:22 PM.

The following user thanked Pichu for this useful post:

Docko412

The following user groaned Pichu for this awful post:

CodingNation
12-14-2011, 02:35 AM #2
KilllerPanda
Wanted Dead or Alive
Originally posted by Sublimity View Post
Random Number Generator.

How to use:
Select your Maximum and Minimum
Select how many times you want a number generated
Press generate

A list of randomly generated based on how many times you want it to generate will appear in the box on the right, when it is complete you will be prompted with a message box telling you it is completed.

This is great to use when you have to generate more than one random number, EG a raffle on here with 10 winners. Instead of using Random.Org and pressing it 10 times you can just generate all at once.

Difficulty: 1/10

Time taken: 10 minutes

Download to .exe file: You must login or register to view this content.

You must login or register to view this content.

Source:

        
Random rnd = new Random();
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
numericUpDown1.Enabled = false;
numericUpDown2.Enabled = false;
numericUpDown3.Enabled = false;
button1.Enabled = false;
int a = Convert.ToInt32(numericUpDown1.Value);
int b = Convert.ToInt32(numericUpDown2.Value);
int c = Convert.ToInt32(numericUpDown3.Value);
for (int counter = 1; counter <= c; counter++)
{
int num = rnd.Next((b - 1), (a + 1));
if (num < 0)
{
num = num * -1;
}
richTextBox1.Text = num + "\n" + richTextBox1.Text;
if (counter == c)
{
button1.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
numericUpDown3.Enabled = true;
MessageBox.Show("Number of generated numbers is " + c, "Completed");
}
}
}


private void checkvalue_Tick(object sender, EventArgs e)
{
if (numericUpDown2.Value >= numericUpDown1.Value)
{
numericUpDown1.Value = numericUpDown2.Value + 1;
}
}
}


As you can see it is a very simple program, to those who are learning hopefully this code teaches you something.


Nice, what is this coded in? I wanna say C#.
12-14-2011, 02:46 AM #3
Pichu
RIP PICHU.
Originally posted by KilllerPanda View Post
Nice, what is this coded in? I wanna say C#.


C#, very simple program. I just got bored and was like why not, I need on my computer anyways for something else...
12-14-2011, 02:49 AM #4
KilllerPanda
Wanted Dead or Alive
Originally posted by Sublimity View Post
C#, very simple program. I just got bored and was like why not, I need on my computer anyways for something else...

See, I started out with Visual Basic and now I've been trying to learn C# but I haven't had time to really learn it. I kinda wish I started out with C# but oh well, this will help me out. :P Thanks :y:
12-14-2011, 02:52 AM #5
Pichu
RIP PICHU.
Originally posted by KilllerPanda View Post
See, I started out with Visual Basic and now I've been trying to learn C# but I haven't had time to really learn it. I kinda wish I started out with C# but oh well, this will help me out. :P Thanks :y:


No problem. I started out with VB as well and found C# difficult to understand at first but somehow it just clicked and I understood what it was I was needing to do to use it... weird I know.

Try and look at my source release for what I was doing with my MW3 Toolkit, there is some good there as you can get a bit of a better grip looking at that.

Try an EBook for C#, there is one someone in Premium, if you can't find it I have it reuploaded to my Mediafire and I can just send to you, I got to chapter 12 and then quit.
12-14-2011, 06:04 AM #6
imo these are pointless. for new programmers I guess it's cool... but like 5 sec bat file... "%random%"

of course you can add limits, but idk just seems pointless. :y: thanks for releasing for beginners though Smile
12-14-2011, 02:57 PM #7
BuC-ShoTz
TeamMvKâ?¢
Originally posted by Team
imo these are pointless. for new programmers I guess it's cool... but like 5 sec bat file... "%random%"

of course you can add limits, but idk just seems pointless. You must login or register to view this content. thanks for releasing for beginners though You must login or register to view this content.

not pointless, i use something similar for my youttube account creator:
Call
    
string birthYear = RandomNum(1920, 198Cool Man (aka Tustin);

Function
    
private readonly Random _rng = new Random();
private string RandomNum(int low, int high)
{
string RandomNumber = Convert.ToString(_rng.Next(low, high + 1));
return RandomNumber;
}
Last edited by BuC-ShoTz ; 12-14-2011 at 03:13 PM.
12-14-2011, 03:02 PM #8
Pichu
RIP PICHU.
Originally posted by ShoTz View Post
not pointless, i use something similar for my youttube account creator:
Call
    
string myNumber = RandomNum(1920, 198Cool Man (aka Tustin);

Function
    
private readonly Random _rng = new Random();
private string RandomNum(int low, int high)
{
string RandomNumber = Convert.ToString(_rng.Next(low, high + 1));
return RandomNumber;
}


Thank you, the whole point of this is to teach them about randoms and such.
12-14-2011, 03:05 PM #9
BuC-ShoTz
TeamMvKâ?¢
Originally posted by Sublimity View Post
Thank you, the whole point of this is to teach them about randoms and such.


no problem, thats what i use to generate a random year, i made a nice random class just for signing up youtube accounts, even makes it with real names...
12-14-2011, 04:04 PM #10
Woof
...hmm
Originally posted by Team
imo these are pointless. for new programmers I guess it's cool... but like 5 sec bat file... "%random%"

of course you can add limits, but idk just seems pointless. :y: thanks for releasing for beginners though Smile

The amount of times I use this, nothing is pointless, there is a use for everything. (depends what you're making of course)

---------- Post added at 11:04 AM ---------- Previous post was at 11:03 AM ----------

Originally posted by ShoTz View Post
no problem, thats what i use to generate a random year, i made a nice random class just for signing up youtube accounts, even makes it with real names...

What do you mean by real names? :p

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo