• Status: Solved
• Priority: Medium
• Security: Public
• Views: 158

# geting 4 random numbers from 100

im working on a prgram called "who doesnt wan to be a millionare" and i working on how to "ask the aduiences" an answer.  i have 50/50 working where 2 answers are removed but i would like to implement how to simulate an audience of 100 giving ther random choice of 4 answers.

how to get 4 random numbers of out a total of 100

e.g at typical result would be:
40,10,30,20
0
gerrymcd
• 7
• 6
• 3
• +2
1 Solution

Commented:
Dim int1 As Integer
Dim int2 As Integer
Dim int3 As Integer
Dim int4 As Integer
Randomize

int1 = Cint((Rnd*99) + 1)
int2 = CInt((Rnd*99) + 1)
int3 = CInt((Rnd*99) + 1)
int4 = CInt((Rnd*99) + 1)

0

Commented:
Sub GetRandomFour()

Dim AnswerPcnt(1 To 4) As Integer
Dim Audience(1 To 100) As Integer
Dim i As Integer

Randomize

For i = 1 To 4
Next i

For i = 1 To 100
i = Int((Rnd * 3) + 1)
Next i

End Sub
0

Commented:
oooops..

0

Commented:

Dim nums(1 To 4) As Integer
Dim choice(1 To 100) As Integer
Dim i As Integer
Dim j As Integer

Randomize

For i = 1 To 100
j = CInt((Rnd * 3) + 1)
nums(j) = nums(j) + 1
Next i
0

Commented:
Sub GetRandomFour()

Dim Audience As Integer
Dim i As Integer
Dim AnswerPcnt(1 To 4) As Integer

Randomize

For i = 1 to 4
Next i

For Audience = 1 To 100
i = Int((Rnd * 3) + 1)
Next Audience

End Sub
0

Commented:
hey Azra, how's it going? ;>)
0

Commented:
Sorry gerry I left that array choice() in there, you dont need it the way i ended up looping through the results.
Hello Foyal, we both are a little slow today I suppose  =)
0

Commented:
yea, my first entry was totally messed up... the second one will work fine though... Since when did Monday start falling on Saturday? LOL ;>)
0

Commented:
My Mondays generally run about a week long, so don't feel bad =)
0

Commented:
Foyal:

As you create AnswerPcnt coming into the subroutine

Dim AnswerPcnt(1 To 4) As Integer

This code is unnessary.

For i = 1 to 4
Next i

As such, your code is now tighter.. <smile>.
0

Commented:
bravo wsh2 <grin>
0

Commented:
wsh2: ooops... I sure do wish that was as bad as it ever gets.... ;>)
see 'ya,
Foyal
0

Commented:
Foyal:
<laughing>.. tell me about it.. somedays the keyboard just does what it wants.

Anyhow.. congrats on your very correct and appropriate.. <hmmmm.. now taking shoes off to count>.. 312 solutions.. <smile> and an <only kidding wink>.
0

Author Commented:
thanks, althought the 4 numbers worked ok but the 4th num seesm to alsways be a 0.

anyway
0

Commented:
what happened to my code
0

Commented:
Gawd.. we ALL missed that.. <sheesh>.. <LOL> and a <wink>. Change this line:

From:

i = Int((Rnd * 3) + 1)

To:

i = Int((Rnd * 4) + 1)

0

Commented:
doh!
0

Commented:
heh
0

Commented:
aarrrrggggggghhhhhhhhh...
LOL ;>)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.