| View previous topic :: View next topic |
| Author |
Message |
coder sal Master Cheater
Reputation: 0
Joined: 11 May 2007 Posts: 304
|
Posted: Sat Nov 10, 2007 3:33 pm Post subject: vb6 how to |
|
|
| How do you generate random numbers in VB6?
|
|
| Back to top |
|
 |
AtheistCrusader Grandmaster Cheater
Reputation: 6
Joined: 23 Sep 2006 Posts: 681
|
Posted: Sat Nov 10, 2007 3:34 pm Post subject: |
|
|
msgbox Rnd(Val(rnd * 100 + 1)
if u want exact
|
|
| Back to top |
|
 |
coder sal Master Cheater
Reputation: 0
Joined: 11 May 2007 Posts: 304
|
Posted: Sat Nov 10, 2007 3:37 pm Post subject: |
|
|
| syntax error...
|
|
| Back to top |
|
 |
AtheistCrusader Grandmaster Cheater
Reputation: 6
Joined: 23 Sep 2006 Posts: 681
|
Posted: Sat Nov 10, 2007 3:38 pm Post subject: |
|
|
msgbox (Rnd(Val(rnd * 100 + 1) )
try this 1
|
|
| Back to top |
|
 |
coder sal Master Cheater
Reputation: 0
Joined: 11 May 2007 Posts: 304
|
Posted: Sat Nov 10, 2007 3:40 pm Post subject: |
|
|
Still syntax error...I got the code its MsgBox (Rnd * 100 + 1) without the other shit. Thnx, I did Text1.Text = (Rnd * 100000) but why is it always a decimal number wtf?
Last edited by coder sal on Sat Nov 10, 2007 3:43 pm; edited 1 time in total |
|
| Back to top |
|
 |
AtheistCrusader Grandmaster Cheater
Reputation: 6
Joined: 23 Sep 2006 Posts: 681
|
Posted: Sat Nov 10, 2007 3:42 pm Post subject: |
|
|
| the thing was i added Val to rnd without puttin another ) in the end
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Nov 10, 2007 4:52 pm Post subject: |
|
|
You should also make a call to Randomize to have a more random output:
| Code: | Private Sub Command1_Click()
Randomize
MsgBox CLng(Rnd * 255)
End Sub |
You can also setup a seed with Randomize which will help 'randomize' the output generated from Rnd.
_________________
- Retired. |
|
| Back to top |
|
 |
XxOsirisxX Grandmaster Cheater Supreme
Reputation: 0
Joined: 30 Oct 2006 Posts: 1597
|
Posted: Sat Nov 10, 2007 9:00 pm Post subject: |
|
|
| Wiccaan wrote: | You should also make a call to Randomize to have a more random output:
| Code: | Private Sub Command1_Click()
Randomize
MsgBox CLng(Rnd * 255)
End Sub |
You can also setup a seed with Randomize which will help 'randomize' the output generated from Rnd. |
This one is good, also will be an "Integer" number because the CLng (Convert to long). That will generate a "random" number between 0~255, I realy don't know if negatives are allowed, i suppose no.
In another hand, i will gave you this code in case you wish to use a defined randoms values.
| Quote: | Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function |
After having Rand as public then you just add this as example..
| Quote: | Randomize
blablabla = Rand(1, 2)
if blablabla = 1 then
msgbox "123"
.... |
So, you put the Lowest and Higher numbers you wants to be "random" between. In this case, where between 1 and 2.
Hopes you undersntad it, and if will not use, at least learn something which is better.
_________________
|
|
| Back to top |
|
 |
Golden Wing Grandmaster Cheater
Reputation: 0
Joined: 29 Aug 2007 Posts: 905
|
Posted: Sat Nov 10, 2007 9:25 pm Post subject: |
|
|
| crap wiccaan and XxOsirisxX beat me to it
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Nov 11, 2007 6:52 am Post subject: |
|
|
| XxOsirisxX wrote: | | That will generate a "random" number between 0~255, I realy don't know if negatives are allowed, i suppose no. |
Negative numbers work.
Also in your code, you should call Randomize as well.
_________________
- Retired. |
|
| Back to top |
|
 |
TheLazyCat Expert Cheater
Reputation: 0
Joined: 29 Sep 2007 Posts: 117 Location: My House with Milk
|
Posted: Wed Nov 14, 2007 8:18 pm Post subject: |
|
|
The easiest would be
| Code: |
Randomize
textbox1.text = Int(Rnd() * 100) ' for the textbox1.text but whatever the output box is |
the * 100 means its a random number 0-99 you can change that
if you put
[/code]textbox1.text = int(Rnd() * 100 + 1) | Code: |
then it would be 1-100 {I think im not certain} |
|
|
| Back to top |
|
 |
|