Solved

geting 4 random numbers from 100

Posted on 2000-04-15
19
146 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

770 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