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-15-2011, 04:43 AM #20
Correy
I'm the Original
Originally posted by Sublimity View Post
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


as good as i am, i wouldnt want to be a programer.. joinery for me, im a active person.. couldnt sit there like 50+ hours a week, maybe as a retirement job thats when ill be doing something lazy lmao.

i think i might create a .dll which updates the program, well tomorrow cause im about to go to bed :p
12-15-2011, 04:52 AM #21
Pichu
RIP PICHU.
Originally posted by Correy View Post
as good as i am, i wouldnt want to be a programer.. joinery for me, im a active person.. couldnt sit there like 50+ hours a week, maybe as a retirement job thats when ill be doing something lazy lmao.

i think i might create a .dll which updates the program, well tomorrow cause im about to go to bed :p


Ohh, well I don't know I'm either going to take the path of being a police officer, programmer or combine the two and try and get into something for things like with the FBI and work in their computer division (Criminal Justice + Computer Science are the two degrees they want you to have for something like that). Smile

I don't know, I will have the four years of college to decide, I'm doing both anyways because if I become a cop then in my free time I can use my programming skills I acquire for personal use and fun and if I go into programming, then hell I am set anyways if I ever decide that programming is boring and I want to make a switch to a cop.
12-15-2011, 05:32 AM #22
Pichu
RIP PICHU.
Originally posted by reScript
I wouldn't want to do it either, I could image myself getting bored as **** after a while.
Reason why I want to look more into game development, atleast I Imagen it being more entertaining.
Anyway scratch all that~ I will never be good enough.

---------- Post added 12-15-2011 at 12:22 AM ---------- Previous post was 12-14-2011 at 11:53 PM ----------


I would use something along these lines.
    

public Random random;
public string nameGenerator(int low, int high)
{
string[] names = {"name1", "name2", "name3"};
string name = names[random.Next(0, names.Length)].ToCharArray() + random.Next(low, high).ToString();
return name;
}


Yea, I get what you mean about game development, if I do take a path towards programming it would just mean adding some more time under my belt but I could most likely use what I learn through Computer Science courses and apply it towards game development.

Only time will tell what I really want to do, I'm on that edge, besides most people choose the job they really want just about half way through college when they are doing two majors they would both enjoy, but I am finding programming more enjoyable.
12-15-2011, 06:11 AM #23
tokzikate
Gym leader
Nice, cleanly written program sublime Smile
Originally posted by Sublimity View Post
.


---------- Post added at 02:11 AM ---------- Previous post was at 02:07 AM ----------

I don't know much about C# but would it be easier if it grabbed the first names, and lastnames, from a txt file?
One txt file for firstnames, and another for lastnames?
That you could have more variety in generated names, and a program that is easier to read Smile
But then again, you know what your doing Winky Winky as your a much better programmer than myself :P
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
12-15-2011, 06:13 AM #24
Pichu
RIP PICHU.
Originally posted by tokzikate View Post
Nice, cleanly written program sublime Smile



---------- Post added at 02:11 AM ---------- Previous post was at 02:07 AM ----------

I don't know much about C# but would it be easier if it grabbed the first names, and lastnames, from a txt file?
One txt file for firstnames, and another for lastnames?
That you could have more variety in generated names, and a program that is easier to read Smile
But then again, you know what your doing Winky Winky as your a much better programmer than myself :P


Or, simply you could just create two class files, one for first names and another for last names and then just pull those in together and use them for management purposes.

Thank you. Happy
Last edited by Pichu ; 12-15-2011 at 06:17 AM.
12-15-2011, 06:16 AM #25
tokzikate
Gym leader
I should probably try to learn C#, and take a break from c++ and vb for a while,
and I know this is off-topic, but was this too harsh? You must login or register to view this content.
Originally posted by Sublimity View Post
Or, simply you could just create two class files, one for first names and another for last names and then just pull those in together and use them for management purposes.
12-15-2011, 06:20 AM #26
Pichu
RIP PICHU.
Originally posted by tokzikate View Post
I should probably try to learn C#, and take a break from c++ and vb for a while,
and I know this is off-topic, but was this too harsh? You must login or register to view this content.


Well VB and C# are essentially the same thing but C# is more practical because it takes use of the syntax so adjustment from C# to Java and vice versa is easier than going from VB to Java and such.

---

No, that wasn't harsh at all. What did you use to decompile his work and get his information? I tried to find something to let me do that and what I find is crap or makes me pay.. Not Happy or Sad
12-15-2011, 06:29 AM #27
tokzikate
Gym leader
yeah I know what you mean, same form names and such, but C# uses ";" at the end of statements.

Yeah I used the IL Disassembler from Microsoft's Visual Studio Package, it works great for decompiling programs made with Visual Studio.
I have Microsoft Visual Studio Ultimate (thanks thepiratebay, saved me $11000 :carlingSmile and IL Disassembler came with it, though there are others out there which you can use Smile I'll have a look for a good one I saw not too long ago
Originally posted by Sublimity View Post
Well VB and C# are essentially the same thing but C# is more practical because it takes use of the syntax so adjustment from C# to Java and vice versa is easier than going from VB to Java and such.

---

No, that wasn't harsh at all. What did you use to decompile his work and get his information? I tried to find something to let me do that and what I find is crap or makes me pay.. Not Happy or Sad
12-15-2011, 06:36 AM #28
Pichu
RIP PICHU.
Originally posted by tokzikate View Post
yeah I know what you mean, same form names and such, but C# uses ";" at the end of statements.

Yeah I used the IL Disassembler from Microsoft's Visual Studio Package, it works great for decompiling programs made with Visual Studio.
I have Microsoft Visual Studio Ultimate (thanks thepiratebay, saved me $11000 :carlingSmile and IL Disassembler came with it, though there are others out there which you can use Smile I'll have a look for a good one I saw not too long ago


Yea, I used to have a good one and an obfuscator that installed itself for Visual Express use and it worked perfectly but then my computer crashed and I forgot what it was called. :/

My computer has somewhat of an issue running their paid version although I may just download it again...

Sigh, I just can't wait for the end of Senior year, that's when I will be getting a laptop, that's when I will be able to do crap that I want to do without lag issues because we are going all out for me.

Stuck on a crap computer, 512mb 2.39gh Intel Pentium

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo