Solved

geting 4 random numbers from 100

Posted on 2000-04-15
19
144 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
Comment Utility
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
Comment Utility
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
Comment Utility
oooops..

0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
Comment Utility
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
Comment Utility
hey Azra, how's it going? ;>)
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
Comment Utility
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
Comment Utility
My Mondays generally run about a week long, so don't feel bad =)
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
bravo wsh2 <grin>
0
 
LVL 3

Expert Comment

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

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
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
Comment Utility
what happened to my code
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
doh!
0
 
LVL 3

Expert Comment

by:fibdev
Comment Utility
heh
0
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
aarrrrggggggghhhhhhhhh...
LOL ;>)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now