Solved

geting 4 random numbers from 100

Posted on 2000-04-15
19
153 Views
Last Modified: 2010-05-02
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
Comment
Question by:gerrymcd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
  • +2
19 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2719105
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
 
LVL 3

Expert Comment

by:Foyal
ID: 2719120
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
        AnswerPcnt(i) = 0
    Next i

    For i = 1 To 100
        i = Int((Rnd * 3) + 1)
        AnswerPcnt(i) = AnswerPcnt(i) + 1
    Next i    
 
    'GroupThatSelectedAnswer1 = AnswerPcnt(1)
    'GroupThatSelectedAnswer2 = AnswerPcnt(2)
    'GroupThatSelectedAnswer3 = AnswerPcnt(3)
    'GroupThatSelectedAnswer4 = AnswerPcnt(4)  
   
End Sub
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2719128
oooops..

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2719130
sorry i misread question:

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
 
LVL 3

Accepted Solution

by:
Foyal earned 50 total points
ID: 2719136
Sub GetRandomFour()

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

    Randomize

    For i = 1 to 4
        AnswerPcnt(i) = 0
    Next i

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

    'GroupThatSelectedAnswer1 = AnswerPcnt(1)
    'GroupThatSelectedAnswer2 = AnswerPcnt(2)
    'GroupThatSelectedAnswer3 = AnswerPcnt(3)
    'GroupThatSelectedAnswer4 = AnswerPcnt(4)

End Sub
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2719139
hey Azra, how's it going? ;>)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2719151
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
 
LVL 3

Expert Comment

by:Foyal
ID: 2719158
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2719164
My Mondays generally run about a week long, so don't feel bad =)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2719279
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
        AnswerPcnt(i) = 0
    Next i

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

Expert Comment

by:fibdev
ID: 2719648
bravo wsh2 <grin>
0
 
LVL 3

Expert Comment

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

Expert Comment

by:wsh2
ID: 2720228
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
 
LVL 2

Author Comment

by:gerrymcd
ID: 2720358
thanks, althought the 4 numbers worked ok but the 4th num seesm to alsways be a 0.

anyway
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2720573
what happened to my code
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2720810
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2720821
doh!
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2721137
heh
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2721574
aarrrrggggggghhhhhhhhh...
LOL ;>)
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question