PDA

Click to See Complete Forum and Search --> : random number


Help ME
Nov 26th, 1999, 11:11 AM
ok. i got a command button and a label. i click the command button. and it will pick a random number from 1 to 1000. and it will change label 1 caption to the number.

Aaron Young
Nov 26th, 1999, 11:29 AM
Private Sub Command1_Click()
Randomize Timer
Label1 = Int(Rnd * 999) + 1
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Nov 26th, 1999, 04:28 PM
Function RandRange(byval Lower as Double, Byval Upper as Double, Optional MyInt as Boolean = True)

Randomize

Select Case MyInt
Case Is = True
RandRange = Int((rnd * (Upper - Lower)) + Lower)
Case Is = False
RandRange = (rnd * (Upper - Lower)) + Lower
End Select
End Function


the above is a function that i wrote for a fractal app.

Syntax is:

RandRange(Lower as double, Upper as double, MyInt as Boolean)

It picks a random number between LOWER and UPPER, if you specify MyInt as false, then it will return a nuber with a decimal: ie. 111343275882.6774439, or something, the default is true (always a whole number returned).

hope this is usefull to someone

------------------

Wossname,
Email me: wossnamex@talk21.com :)

Compwiz
Nov 27th, 1999, 03:33 AM
Aaron, what would happen if you didn't put a Randomize Timer in it?

------------------
Tom Young, 14 Year Old
tyoung@stny.rr.com
ICQ: 15743470 (http://wwp.icq.com/15743470) Add Me (http://wwp.icq.com/scripts/search.dll?to=15743470) ICQ Me (http://wwp.icq.com/scripts/contact.dll?msgto=15743470)
AIM: TomY10 (http://www.aol.com/aim/aim30.html)
PERL, JavaScript and VB Programmer

CarlosTheJackal
Nov 27th, 1999, 08:48 AM
hey- im not Aaron, but i can answer your question Compwiz...If you didnt put in randomize timer it would pick the same "random" number each time.Randomize Timer sets the "seed" value of the randomizer based on the time of day,so it will always be different.Hope to have helped,

Thnx for your time,
CarlosTheJackal

Compwiz
Nov 27th, 1999, 09:37 PM
Kewl, thanx. I didn't mean to address the question to just Aaron, but he made the code so... thanx!

[This message has been edited by Compwiz (edited 11-28-1999).]