New topic: when button is pressed generate random number?
<http://forums.realsoftware.com/viewtopic.php?t=38730> Page 1 of 1 [ 10 posts ] Previous topic | Next topic Author Message iDoiStuff Post subject: when button is pressed generate random number?Posted: Fri Apr 22, 2011 4:32 pm Joined: Thu Apr 14, 2011 9:03 pm Posts: 9 how to make it so when button is pressed, generate random number in textfield1? I want the random number to be 5 numbers long each time. (I am using this as a random number picker/generator) how would I do this? Top Lazze Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 4:38 pm Joined: Thu Jul 27, 2006 7:32 am Posts: 95 Location: Esbjerg, Denmark From the Language Reference Code:Dim r as New Random Statictext1.Text=Str(r.InRange(0,1000)) _________________ Why make it simple if it can be made complicated? http://www.laniesoftware.com Top DaveS Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 4:58 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 2933 Location: San Diego, CA actually to meet the OP requirements Code:: Dim r as New Random Statictext1.Text=Str(r.InRange(10000,99999)) _________________ Dave Sisemore MacPro, OSX 10.6.4 RB2009r5.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top Lazze Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 5:11 pm Joined: Thu Jul 27, 2006 7:32 am Posts: 95 Location: Esbjerg, Denmark My point was merely to point out that a simple search in the LR would have explained it... _________________ Why make it simple if it can be made complicated? http://www.laniesoftware.com Top DaveS Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 5:26 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 2933 Location: San Diego, CA Yeah.... I'm amazed at the number of people who never bother to use the documentation..... RTMF ... if you know what I mean _________________ Dave Sisemore MacPro, OSX 10.6.4 RB2009r5.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top iDoiStuff Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 6:21 pm Joined: Thu Apr 14, 2011 9:03 pm Posts: 9 okay, well I decided to make it 25 long instead of 5. I am making this for a minecraft seed gen. I decided I want it to do random numbers AND letters which always equal 25 characters long. I have tried doing this myself, but couldn't get it working.. Top JShaffer Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 6:56 pm Joined: Fri Jan 23, 2009 9:18 am Posts: 70 Location: Summerfield, Florida iDoiStuff wrote:okay, well I decided to make it 25 long instead of 5. decided I want it to do random numbers AND letters which always equal 25 characters long. This is one way to generate the random string. Code: // Generate a random string of 25 characters Const passwordLength = 25 dim chars as String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" dim chArray() as String = chars.Split("") Dim randomString as String dim r as new random dim arrayLength as integer = chArray.Ubound dim randomCharacter as Integer for i as integer = 1 to passwordLength randomCharacter = r.InRange(0, arrayLength) randomString = randomString + chArray(randomCharacter) next label1.Text = randomString Jim Top doofus Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 6:57 pm Joined: Thu Sep 10, 2009 2:50 am Posts: 104 Location: Santa Cruz, CA, USA iDoiStuff wrote:I decided I want it to do random numbers AND letters which always equal 25 characters long. Code: dim sa() As String dim r As new Random dim v As integer for i As integer = 1 to 25 v = r.InRange(65, 90 + 10) if v > 90 then v = v - (90 + 1 - 48) sa.Append Chr(v) next TextField1.Text = Join(sa, "") That'll make uppercase letters, for lowercase change the ascii values... Code: ... v = r.InRange(97, 122 + 10) if v > 122 then v = v - (122 + 1 - 48) ... Top iDoiStuff Post subject: Re: when button is pressed generate random number?Posted: Fri Apr 22, 2011 8:08 pm Joined: Thu Apr 14, 2011 9:03 pm Posts: 9 thanks! it works great. now is it possible to make it so it waits 3 seconds then displays the generated string? Top timhare Post subject: Re: when button is pressed generate random number?Posted: Sat Apr 23, 2011 12:34 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 9722 Location: Portland, OR USA Use a timer. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 10 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
