Solved

geting 4 random numbers from 100

Posted on 2000-04-15
19
149 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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

685 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