Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Nov 2002
    Location
    Midlands, England
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB.Net (Microsoft Visual Studio)

    ive written a program to generate 100 random integer numbers in the range of 1 to 6. For each value i need to count its occurence and store in an element of an array, and i don't know how do to this. Can n e one help.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VB.Net (Microsoft Visual Studio)

    This is a possible solution for VB/VBA. I don't know .Net (there is a separate forum for .Net):

    ' Array with random numbers
    Dim arintRandomNumbers(1 To 100) As Integer
    ' Array with counts
    Dim arintCount(1 To 6) As Integer
    ' Loop counter
    Dim i As Integer

    ' Fill array with random numbers
    For i = 1 To 100
    arintRandomNumbers(i) = Int(Rnd * 6 + 1)
    Next i

    ' Make sure arintCount is initialized to zeros
    Erase arintCount
    ' Compute counts
    For i = 1 To 100
    arintCount(arintRandomNumbers(i)) = arintCount(arintRandomNumbers(i)) + 1
    Next i

    ' Display counts
    For i = 1 To 6
    Debug.Print arintCount(i)
    Next i

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •