Post: [C#] Random Strings
06-13-2011, 10:19 PM #1
Correy
I'm the Original
(adsbygoogle = window.adsbygoogle || []).push({}); in this thread i will be showing you how to create and code Random commands using Strings in Visual Studio 2011 C#


Using strings which are already set
Add this code to you're option you want to add it to, in this case i will be adding it to a public void to create some randomise Label text..
    
{
String[] strLabel = {
"First Label",
"Second Label",
"Third Label",
"Fourth Label"
};
Random r = new Random();
int iSelect = r.Next(0, 3);
lblRandom.Text = strLabel[iSelect];
}

now, if you were going to add strings make sure you change the 'r.Next(COLOR="red"]0,3[/COLOR])' as this shows how many strings you want to generate.


you can use this to also do commands, for example..
    
button1 = new Button
{
String[] button = {
command one();,
command two();,
command three();,
command four();"
};
Random r = new Random();
int iSelect = r.Next(0, 3);
button1_click = button[iSelect];
}


Video Example Here.



it's a simple code which i came up with in a test form, it may not be the best but it certainly works and Can come in use.
thanks for reading.
(adsbygoogle = window.adsbygoogle || []).push({});
06-16-2011, 08:59 PM #11
Correy
I'm the Original
Originally posted by kiwimoosical View Post
Then why did you title this random strings?


because that is a string, theres fixed strings but it randomises the strings
06-18-2011, 11:24 PM #12
Josh_ox3
Treasure hunter
Guid.NewGuid().ToString("f").Substring(1, 7) Even Easier Happy
06-19-2011, 01:09 PM #13
Correy
I'm the Original
Originally posted by ox3 View Post
Guid.NewGuid().ToString("f").Substring(1, 7) Even Easier Happy


thanks, but what's that do =D ?
06-19-2011, 04:47 PM #14
Josh_ox3
Treasure hunter
Originally posted by xCorrey
thanks, but what's that do =D ?


Creates a 7 letter/number long text that are lower case
06-20-2011, 01:03 AM #15
Correy
I'm the Original
Originally posted by ox3 View Post
Creates a 7 letter/number long text that are lower case


thanks bro, nice code :Y:

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo