Solved

geting 4 random numbers from 100

Posted on 2000-04-15
19
148 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
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.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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