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-16-2011, 08:29 AM #47
Chrom3D
Big Sister
I'll belive this will come usefull in later on =D

Thanks for the source code.
12-17-2011, 12:59 AM #48
Pichu
RIP PICHU.
Originally posted by Chrom3D View Post
I'll belive this will come usefull in later on =D

Thanks for the source code.


No problem, I'm trying to find my source for checking application version via FTP right now... If I can find it then I will release that, with the source of mine it would allow you to prompt users to update your application.
12-18-2011, 06:43 AM #49
tokzikate
Gym leader
A quick question, why do you use "(b - 1)" instead of just "b" ?

Originally posted by Sublimity View Post
Random Number Generator.
Source:
    
for (int counter = 1; counter <= c; counter++)
{
int num = rnd.Next([I][COLOR=#ff0000][U][B](b - 1)[/B][/U][/COLOR][/I], (a + 1));
}

12-18-2011, 09:01 PM #50
Pichu
RIP PICHU.
Originally posted by tokzikate View Post
A quick question, why do you use "(b - 1)" instead of just "b" ?


Minimum and Maximum, 1,2 lets say.

When you are using the random the program would choose the lower number if they were next to each other without looking at the maximum, when I raised it 1 and lowered it 1 so min = 0 and max = 3 it then looked at the numbers 1 and 2.

Give it a try and remove the -1 you will see what I mean.
12-23-2011, 10:24 PM #51
Pichu
RIP PICHU.
Video tutorial added for those who need help.

Starting a video series, uploading a new tutorial every Friday.

Please subscribe. Smile

[YT]FreeTechVids[/YT]

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo