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, 05:55 PM #11
BuC-ShoTz
TeamMvKâ?¢
Originally posted by reScript View Post

What do you mean by real names? :p


You must login or register to view this content.You must login or register to view this content.You must login or register to view this content.
You must login or register to view this content.You must login or register to view this content.You must login or register to view this content.
12-14-2011, 08:36 PM #12
Woof
...hmm
Originally posted by ShoTz View Post


Coolio.
Wait a minute though Youtube accounts have image verification on registration, how did you bypass it?
Or is it a secret? xD
12-14-2011, 10:14 PM #13
what for? raffle's is the only thing I can think of :p
12-15-2011, 01:16 AM #14
Pichu
RIP PICHU.
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...


Mind if I get a look at the source? I haven't spent the time to learn much of anything dealing with webrequest, if I could look at some sort of working source that is recent maybe I can figure it out and start working more with application to web.

Closest thing to connecting an application to the web was when I made something that checks a xml files uploaded in your ftp on whether or not that version written in is the same in the application.

Originally posted by reScript View Post
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 ----------


What do you mean by real names? :p


Yea, it helps a lot. Happy
12-15-2011, 03:49 AM #15
Pichu
RIP PICHU.
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...


Originally posted by ShoTz View Post
You must login or register to view this content.You must login or register to view this content.You must login or register to view this content.
You must login or register to view this content.You must login or register to view this content.You must login or register to view this content.


Do you use Fakenamegenerator.com as your source for the names?
12-15-2011, 04:17 AM #16
Correy
I'm the Original
Originally posted by Sublimity View Post
Do you use Fakenamegenerator.com as your source for the names?


nope, all listen random strings.. almost exactly like this, but a little different..
    
String[] strLabel = {
"First Label",
"Second Label",
"Third Label",
"Fourth Label"
};
Random r = new Random();
int iSelect = r.Next(0, 3);
lblRandom.Text = strLabel[iSelect];


and heres just a quick one if you need it..
    
private void GenerateNames()
{
Random i = new Random();
string names = "Bob|Simon|Paul|Peter|Corey";
string Name = strTok( names, "|" );
string Generated( Name[ i.Next( Name.size )] );
}


i gave him one like that but he said he dont like scrolling across :yuno: :p
Last edited by Correy ; 12-15-2011 at 04:21 AM.
12-15-2011, 04:27 AM #17
Pichu
RIP PICHU.
Originally posted by Correy View Post
nope, all listen random strings.. almost exactly like this, but a little different..
    
String[] strLabel = {
"First Label",
"Second Label",
"Third Label",
"Fourth Label"
};
Random r = new Random();
int iSelect = r.Next(0, 3);
lblRandom.Text = strLabel[iSelect];


and heres just a quick one if you need it..
    
private void GenerateNames()
{
Random i = new Random();
string names = "Bob|Simon|Paul|Peter|Corey";
string Name = strTok( names, "|" );
string Generated( Name[ i.Next( Name.size )] );
}


i gave him one like that but he said he dont like scrolling across :yuno: :p


Ohh, I see. I prefer scrolling across but when I post code I try and not to set it up like that for users to see what I am actually doing.

I still need to learn httpwebrequest, I got very lazy and skipped that although I did learn how to check to see if application version matches that of an xml file that is uploaded via ftp. Smile

(Going to release that source when I find it again)
12-15-2011, 04:30 AM #18
Correy
I'm the Original
Originally posted by Sublimity View Post
Ohh, I see. I prefer scrolling across but when I post code I try and not to set it up like that for users to see what I am actually doing.

I still need to learn httpwebrequest, I got very lazy and skipped that although I did learn how to check to see if application version matches that of an xml file that is uploaded via ftp. Smile

(Going to release that source when I find it again)


yeah i did that, but mine was from the .exe, cant quit remember how but something like a web contained script, then it checked the version and if it said latest update > than current version it would then redirect to a direct download, pretty poor if you ask me.. but i made that as a start off from back when i first started to code Smile
12-15-2011, 04:40 AM #19
Pichu
RIP PICHU.
Originally posted by Correy View Post
yeah i did that, but mine was from the .exe, cant quit remember how but something like a web contained script, then it checked the version and if it said latest update > than current version it would then redirect to a direct download, pretty poor if you ask me.. but i made that as a start off from back when i first started to code Smile


Yea, mine just fetched the xml and read it and then checked to see if the application version >= the XML version, if it was less than then it would prompt the user to update letting them know a new version was out.

I was working on something to allow the user to select where they wanted it downloaded so I didn't have to use System.Diagnostics.Process.Start("http:"); bs crap and then have it download through their internet browser which depending upon what you were using, it was slow or fast.

Since my FTP ran out on me I decided not to finish writing that but maybe if I do program something worthy enough in the near future and have FTP I might do that. Smile

----
I can't wait till next year, I will be going to college for computer science and criminal justice courses, more excited about the computer science though. :P

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo