PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Fill x Numbers with Random numbers-VBForums
Results 1 to 23 of 23

Thread: Fill x Numbers with Random numbers

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Fill x Numbers with Random numbers

    hi, first would like to say am glad there are still active members and forum on VB6

    ok, here is what i like to ask - i hv a value(100) and would like to fill it All into an array(of 30). their range should be in between 1 to 6 each and total up 100 after filling all of them.

    i hv try my it on my own, but it will either not reach 100 or exceed 100 :/

    For i = 0 To 29
    intRandom(i) = RandomNumber(6, 1)
    Next

    thanks in advance.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,041

    Re: Fill x Numbers with Random numbers

    I think you are asking that when the 30 numbers (random) are added up, they need to equal 100, correct?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by SamOscarBrown View Post
    I think you are asking that when the 30 numbers (random) are added up, they need to equal 100, correct?
    yes,they need to be 30 arrays with random numbers from 1 to 6. and when all 30 is fill-up, they are equal to 100.

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,041

    Re: Fill x Numbers with Random numbers

    Whew....that is an interesting challenge, especially how those 30 values are RANDOM. If you don't get help on this today, I may see if I can get the gray matter moving and attempt a solution. Interesting.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,097

    Re: Fill x Numbers with Random numbers

    All your current code is doing is 'hoping' that your 30 random numbers add up to 100. I think you need to put a bit more thought into it, have another try, and then ask for help when you get stuck.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by ColinE66 View Post
    All your current code is doing is 'hoping' that your 30 random numbers add up to 100. I think you need to put a bit more thought into it, have another try, and then ask for help when you get stuck.
    well, i hv try many times and i believe could be done in a better way and there should be some example online. my idea is to fill up few then minus the 100 from the total filled and maybe adjust the random range(less than 6 as max value) and so on to fill all of them. but with that way, the lower array will be less than the top making it not evenly spread.

    thanks,

  7. #7
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,097

    Re: Fill x Numbers with Random numbers

    Well that's pretty much what you'll have to do because what you are asking is not possible; you can't have 30 random numbers adding up to 100 unless you get lucky! Therefore you'll have to influence the outcome in some way. Show us your code for that...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by ColinE66 View Post
    Well that's pretty much what you'll have to do because what you are asking is not possible; you can't have 30 random numbers adding up to 100 unless you get lucky! Therefore you'll have to influence the outcome in some way. Show us your code for that...
    well, i dont hv that now as hv delete them since its 'not working'. the other way i think it to 'cheat' by using few manual template(30 arrays that total 100) and randomly select one, and shuffle them.

    thanks,

  9. #9
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,489

    Re: Fill x Numbers with Random numbers

    Let me suggest an algorithm.
    1. Fill the 30 array items with 3s (number three) so that they all add up to 100. Wait, this is 90! Ok, put 10 fours so that Sum(A[i], i:=1 to 30) = 100
    2. Generate a random value V from 1 to 6
    3. Generate two random indexes I and J from 0 to 29
    4. Add V to A[I] and substract V from A[J]
    5. Iterate this 30 * 30 times (hint, array size, hint)
    6. You have an array of random numbers that add up to 100
    7. Postprocess A so that values are within 1 to 6 range

    Last step 7. I'll leave it to you to figure it out :-))

    cheers,
    </wqw>

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,661

    Re: Fill x Numbers with Random numbers

    Ok, just seeing this. First, and foremost, 30 numbers ranging from 1 to 6 that sum to 100 will never be Uniform Random (which is what I believe you're suggesting). They can be Skewed Random, which pulls us into an entirely different area. For a set number of integers (say 30) with a specific range (say 1 to 6) to have a Uniform Random distribution, the mid-point of the range (3.5) times the number of integers (30) must equal the total your after ... and 3.5 times 30 = 105 (not 100).

    Therefore, if you're truly wanting what you suggest, the first order of business is to figure out from which skewed distribution you're pulling your random number: Poisson, Gauss with a skew value, logarithmic, etc. There are many to choose from. Possibly you even want to bracket part of one of those skewed curves. And, from there, you can start devising your algorithm to always sum to a specific value.

    Also, you will need to decide if the Rnd function is good enough for you, or whether you wish to use the more robust CryptGenRandom (or other) API call (where you get more robust random numbers). And, again, in any of those cases, the results will need to be transformed such that they come from your skewed distribution.

    -----------

    Dealing with random numbers is never as straightforward as people think. And when you want them from a skewed distribution, it gets even more complex.

    Good Luck,
    Elroy

    -----------

    EDIT1: WOW, it took me 30 minutes to make that post ... ran into one of those weird character combinations that wouldn't let me make the post. The bad word filters here apparently really get sideways at times.

    EDIT2: Just as an FYI, pretty much all random-type functions (Rnd, CryptGenRandom, etc) assume that Uniform Random distribution, within their defined range.
    Last edited by Elroy; Aug 3rd, 2019 at 10:01 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,661

    Re: Fill x Numbers with Random numbers

    Another option to build your skewed distribution would be to define the skew proportions for each of your values. For instance, you have stated you want integers from 1 to 6 and you want 30 of them to sum to 100. We could use this information to back into what we want.

    For instance, first, we know we want a mean of 3.33... (100 / 30). That will always be true regardless of the actual numbers, because the mean = total/n, which is 100/30.

    From there, we must assign proportions to each of our allowed numbers (1 to 6) such that their weighted proportions sum to 3.33.... Unweighted proportions (i.e., a Uniform Distribution) will sum to 3.5, as follows:

    Code:
    Number  Proportion            Product
      1             .16666...           .16666...
      2             .16666...           .33333...
      3             .16666...           .5
      4             .16666...           .66666...
      5             .16666...           .83333...
      6             .16666...          1.0
    
        Sum of proportion products = 3.5 (not 3.33....)

    Therefore, we must come up with a set of proportions which sum of proportion products = 3.33....

    The easiest way is to just tamper with the most influential (the 6). We know that 3.5 - 3.33... = .166...
    Therefore, we could just do a bit of algebra, shaving .1666 from 1.0, and then back into the proportion for 6:

    1.0 - .166... = .8333...
    .8333 / 6 = .138888...

    Therefore, if we make .13888... for our proportion for 6, our problem is solved:

    Code:
    Number  Proportion            Product
      1             .16666...           .16666...
      2             .16666...           .33333...
      3             .16666...           .5
      4             .16666...           .66666...
      5             .16666...           .83333...
      6             .13888...           .83333...
    
        Sum of proportion products = 3.33...
    From there, we could use Rnd (or CryptGenRandom) and generate 30 random numbers from 1 to 6 that summed to 100. We'd know going in that the value of 6 would be skewed (occurring slightly less frequently than the others), but, with a bit of thought we could get to where we wanted to be.

    -------

    Just one idea for how to simply skew a distribution.

    Elroy

    -------

    EDIT1: I think this part is obvious, but maybe not. Even after implementing our skew in the random numbers, we'd still have work to guarantee they summed to 100 each time. Alternatively, we could implement our skew, and just take the 30 numbers we got. They wouldn't necessarily sum to 100 each time, but, over the long-run, the average sum would be 100 (if we implemented the skew correctly). QED.

    EDIT2: FYI, this really isn't a VB6 questions. It's more of a straightforward random number theory question.
    Last edited by Elroy; Aug 3rd, 2019 at 10:39 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    @wqweto @Elroy thanks alot for the info, will check out CryptGenRandom later. not as i will need it as i dont need a real RNG, just like to learn something new

    both your suggestion is good, but very complex, so i actually did what i mention earlier - make few fix template put them in DB, random to select which template to use, and then randomly shuffle them.

    i understand this is 'cheating', but its ok as long a cat can catch a mouse, its a good cat ;p

    thanks everyone (y)

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,661

    Re: Fill x Numbers with Random numbers

    Just recognize that, with a template (table) you shuffle, you will always have the same number of 1s, 2s, 3s, etc. Also, as I outlined, your distribution will always have a bit of skew built into it (probably a few less 6s, just because that's the easiest way to get your sum to 100, and not 105).
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by Elroy View Post
    Just recognize that, with a template (table) you shuffle, you will always have the same number of 1s, 2s, 3s, etc. Also, as I outlined, your distribution will always have a bit of skew built into it (probably a few less 6s, just because that's the easiest way to get your sum to 100, and not 105).
    hi, skew is ok as long its not skew at top(mid or bottom) every time. with the method mention it looks very natural to a normal user.

    thanks,

  15. #15
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,661

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by aboka View Post
    hi, skew is ok as long its not skew at top(mid or bottom) every time.
    Ohhh, to have the skew be different each time pushes you back into a very complex situation. I don't think I'll even go there. Just as a trivial example, you'd have to forego many more 1s than 6s to keep your sum at 100. So, how does that affect your skew? See? It's not straightforward.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  16. #16
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,489

    Re: Fill x Numbers with Random numbers

    Here is a straighforward attempt

    thinBasic Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Randomize
    5. End Sub
    6.  
    7. Private Sub Form_Click()
    8.     Dim A(0 To 29)  As Long
    9.    
    10.     FillArray A, 100
    11.     SuffleArray A, 1, 6, 30& * 30 * 30
    12.     DumpArray A
    13. End Sub
    14.  
    15. Private Sub FillArray(A() As Long, ByVal TotalSum As Long)
    16.     Dim lIdx        As Long
    17.     Dim lSum        As Long
    18.    
    19.     For lIdx = 0 To UBound(A)
    20.         A(lIdx) = Int((lIdx + 1) * TotalSum / (UBound(A) + 1) - lSum)
    21.         lSum = lSum + A(lIdx)
    22.     Next
    23.     Debug.Assert lSum = TotalSum
    24. End Sub
    25.  
    26. Private Sub SuffleArray(A() As Long, ByVal Min As Long, ByVal Max As Long, ByVal Iters As Long)
    27.     Dim lIdx        As Long
    28.     Dim lJdx        As Long
    29.     Dim lVal        As Long
    30.    
    31.     Do While Iters > 0
    32.         '--- note: random index in 0 to UBound(A) interval w/o bias from Round-ing
    33.         lIdx = Int(Rnd * (UBound(A) + 1))
    34.         lJdx = Int(Rnd * (UBound(A) + 1))
    35.         lVal = A(lIdx) - 1
    36.         If lVal > Max - A(lJdx) Then
    37.             lVal = Max - A(lJdx)
    38.         End If
    39.         If lVal > 0 Then
    40.             lVal = 1 + Int(Rnd * lVal)
    41.             A(lIdx) = A(lIdx) - lVal
    42.             A(lJdx) = A(lJdx) + lVal
    43.             Iters = Iters - 1
    44.         End If
    45.     Loop
    46. End Sub
    47.  
    48. Private Function DumpArray(A() As Long) As String
    49.     Dim lIdx        As Long
    50.     Dim lSum        As Long
    51.     Dim C(0 To 255) As Long
    52.    
    53.     For lIdx = 0 To UBound(A)
    54.         Debug.Print A(lIdx) & ", ";
    55.         lSum = lSum + A(lIdx)
    56.         C(A(lIdx)) = C(A(lIdx)) + 1
    57.     Next
    58.     For lIdx = 1 To 6
    59.        Debug.Print "C" & lIdx & "=" & C(lIdx) & ", ";
    60.     Next
    61.     Debug.Print "Sum=" & lSum
    62. End Function
    Only Elroy can tell what is the skew here though :-))

    cheers,
    </wqw>

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by wqweto View Post
    Here is a straighforward attempt

    thinBasic Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim A(0 To 29)  As Long
    5.    
    6.     Randomize
    7.     FillArray A, 100
    8.     DumpArray A
    9.     SuffleArray A, 1, 6, 30 * 30
    10.     DumpArray A
    11. End Sub
    12.  
    13. Private Sub FillArray(A() As Long, ByVal TotalSum As Long)
    14.     Dim lIdx        As Long
    15.     Dim lSum        As Long
    16.    
    17.     For lIdx = 0 To UBound(A)
    18.         A(lIdx) = Int((lIdx + 1) * TotalSum / (UBound(A) + 1) - lSum)
    19.         lSum = lSum + A(lIdx)
    20.     Next
    21.     Debug.Assert lSum = TotalSum
    22. End Sub
    23.  
    24. Private Sub SuffleArray(A() As Long, ByVal Min As Long, ByVal Max As Long, ByVal Iters As Long)
    25.     Dim lIdx        As Long
    26.     Dim lJdx        As Long
    27.    
    28.     Do While Iters > 0
    29.         '--- note: random index in 0 to UBound(A) interval w/o bias from Round-ing
    30.         lIdx = Int(Rnd * (UBound(A) + 1))
    31.         lJdx = Int(Rnd * (UBound(A) + 1))
    32.         If A(lIdx) > Min And A(lJdx) < Max Then
    33.             A(lIdx) = A(lIdx) - 1
    34.             A(lJdx) = A(lJdx) + 1
    35.             Iters = Iters - 1
    36.         End If
    37.     Loop
    38. End Sub
    39.  
    40. Private Function DumpArray(A() As Long) As String
    41.     Dim lIdx        As Long
    42.     Dim lSum        As Long
    43.    
    44.     For lIdx = 0 To UBound(A)
    45.         Debug.Print A(lIdx) & ", ";
    46.         lSum = lSum + A(lIdx)
    47.     Next
    48.     Debug.Print "Sum=" & lSum
    49. End Function
    Only Elroy can tell what is the skew here though :-))

    cheers,
    </wqw>
    That would be the best method if its not because it show 'too many duplicates'(3,3,4....) -
    3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, Sum=100
    5, 5, 4, 6, 3, 3, 4, 1, 1, 3, 3, 6, 4, 2, 6, 5, 2, 2, 6, 3, 4, 2, 2, 2, 4, 3, 2, 2, 3, 2, Sum=100
    3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, Sum=100
    1, 2, 3, 4, 4, 3, 5, 5, 1, 5, 5, 5, 2, 1, 2, 3, 4, 4, 2, 4, 3, 5, 5, 1, 3, 2, 5, 2, 4, 5, Sum=100
    3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, Sum=100
    2, 5, 4, 5, 1, 6, 3, 1, 6, 4, 1, 5, 4, 4, 1, 3, 3, 1, 4, 4, 5, 3, 2, 2, 1, 2, 5, 2, 6, 5, Sum=100

    Thanks for the try thou

  18. #18
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,097

    Re: Fill x Numbers with Random numbers

    Quick stab: Basically adjusts the range of numbers that can be picked from based upon the current Running Average, so that it converges on 3.333. The final number is added 'manually' to make up the 100.



    Code:
    Private Sub Command1_Click()
    Dim i As Long, ThisPick As Long, RunningTotal As Long, RunningAverage As Double, MinNum As Long, MaxNum As Long
    
       MaxNum = 6
       MinNum = 1
       
       For i = 1 To 29
       
          ThisPick = Int((MaxNum * Rnd) + MinNum)
          RunningTotal = RunningTotal + ThisPick
          RunningAverage = RunningTotal / i
          
          Debug.Print "Picked " & ThisPick;
          
          Debug.Print ": Running Total is " & RunningTotal & ", Running Average is " & RunningAverage;
          If RunningAverage > 100 / 30 Then
             Debug.Print ": We need to get the average down!";
             MinNum = 1
             MaxNum = MaxNum - 1
             If MaxNum < 0 Then MaxNum = 0
          Else
             Debug.Print ": We need to get the average up!";
             MinNum = MinNum + 1
             If MinNum > 6 Then MinNum = 6
             MaxNum = 6 - MinNum + 1
          End If
          Debug.Print "...Next time, pick from "; MinNum & " to " & MinNum + MaxNum - 1
          
       Next i
       Debug.Print "The last number we need is a " & 100 - RunningTotal
    End Sub
    A few test runs:
    6,1,3,5,3,3,2,2,4,6,1,5,2,6,2,3,1,5,6,1,2,6,4,2,2,4,1,5,5, + 2 = 100
    2,6,4,2,2,4,4,1,6,1,4,5,1,5,3,5,2,1,4,5,1,4,3,4,5,1,5,4,2, + 4 = 100
    3,2,4,5,2,3,3,5,1,4,4,4,5,1,3,5,3,1,4,4,4,5,1,2,6,1,2,3,6, + 4 = 100
    6,3,4,3,2,1,5,2,3,5,2,3,3,6,1,4,5,2,5,1,3,3,6,2,3,3,6,1,4, + 3 = 100
    3,3,6,2,2,2,6,1,5,5,1,6,2,3,1,3,5,5,1,5,4,1,2,3,4,6,1,3,4, + 5 = 100
    6,3,1,6,1,1,6,4,3,2,3,5,2,6,2,1,6,1,3,5,2,4,6,2,2,5,2,5,3, + 2 = 100
    3,2,3,5,5,1,5,1,4,3,6,1,2,6,3,3,6,3,2,1,4,6,3,2,6,3,2,2,5, + 2 = 100
    6,1,4,1,3,3,6,2,3,5,2,3,3,4,6,1,6,1,3,5,2,3,6,1,6,2,3,2,5, + 2 = 100
    3,4,3,4,1,6,1,2,4,5,5,1,2,6,1,2,6,4,5,1,3,6,1,3,5,2,5,1,6, + 2 = 100
    3,3,3,6,1,4,6,1,2,2,6,2,4,4,1,5,3,4,5,1,5,1,4,6,2,2,3,3,5, + 3 = 100
    4,4,2,5,1,6,2,3,1,4,3,6,2,3,4,5,1,5,4,1,5,1,6,4,3,2,1,2,6, + 4 = 100
    5,5,1,1,3,3,4,6,1,5,4,1,6,4,1,2,5,1,5,4,3,2,4,5,1,3,3,4,6, + 2 = 100
    Last edited by ColinE66; Aug 3rd, 2019 at 02:55 PM. Reason: Added a few sample runs...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  19. #19
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,489

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by aboka View Post
    That would be the best method if its not because it show 'too many duplicates'(3,3,4....) -
    3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, Sum=100
    5, 5, 4, 6, 3, 3, 4, 1, 1, 3, 3, 6, 4, 2, 6, 5, 2, 2, 6, 3, 4, 2, 2, 2, 4, 3, 2, 2, 3, 2, Sum=100
    3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, Sum=100
    1, 2, 3, 4, 4, 3, 5, 5, 1, 5, 5, 5, 2, 1, 2, 3, 4, 4, 2, 4, 3, 5, 5, 1, 3, 2, 5, 2, 4, 5, Sum=100
    3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, Sum=100
    2, 5, 4, 5, 1, 6, 3, 1, 6, 4, 1, 5, 4, 4, 1, 3, 3, 1, 4, 4, 5, 3, 2, 2, 1, 2, 5, 2, 6, 5, Sum=100

    Thanks for the try thou
    Just edited the snippet above to increase the shuffle. Now its also dumping counts of 1s, 2s, etc. (stats) and it LGTM
    Code:
    1, 4, 4, 6, 2, 2, 4, 6, 5, 3, 4, 1, 4, 4, 6, 5, 1, 3, 1, 1, 4, 2, 1, 1, 3, 6, 3, 5, 2, 6, C1=7, C2=4, C3=4, C4=7, C5=3, C6=5, Sum=100
    5, 2, 6, 6, 1, 6, 5, 6, 5, 3, 3, 6, 1, 1, 2, 1, 3, 4, 2, 1, 1, 1, 6, 3, 3, 4, 3, 4, 4, 2, C1=7, C2=4, C3=6, C4=4, C5=3, C6=6, Sum=100
    6, 3, 6, 1, 3, 6, 3, 2, 3, 2, 1, 2, 3, 1, 4, 5, 4, 5, 5, 1, 6, 3, 4, 1, 2, 2, 2, 4, 4, 6, C1=5, C2=6, C3=6, C4=5, C5=3, C6=5, Sum=100
    3, 1, 6, 4, 1, 1, 2, 5, 1, 1, 6, 2, 1, 1, 6, 6, 4, 6, 3, 1, 6, 2, 3, 1, 3, 6, 6, 2, 6, 4, C1=9, C2=4, C3=4, C4=3, C5=1, C6=9, Sum=100
    Seems a little biased to 1s for no apparent reason. Probably still not exactly "fair' distribution.

    cheers,
    </wqw>

  20. #20
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,661

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by wqweto View Post
    Probably still not exactly "fair' distribution.
    If the mean (average) of the range you're after (in this case, average of 1,2,3,4,5,6) times the N your after (in this case, 30) doesn't equal the total you're after, (in this case, 100), it's never going to be a "fair" (i.e., uniform, i.e., flat) distribution.

    aboka, could set up some Monte-Carlo trials and watch the distributions (along with percentages) for 1s, 2s, 3s, 4s, 5s, & 6s. This would be easy. Just set up an outer loop that kept pulling samples of 30 (which summed to 100) over and over, counting the 1s, 2s, 3s, 4s, 5s, & 6s each time, and figuring out the proportions of each one. Over time, the proportions, along with any bias, will become evident.

    But, I'm unclear on how much any of this matters for aboka, so I'll leave it to him to perform this Monte-Carlo test.

    (I thought of linking the Wikipedia page for Monte-Carlo Method, but it's too involved. Simply, the Monte-Carlo method is doing something over and over and over (possibly 1000s or millions of times) and accumulating the results to see what happens. In some cases, this is easier to accomplish, although not strictly speaking a mathematical proof.)

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    thanks again Everyone for sharing your knowledge here

  22. #22
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,041

    Re: Fill x Numbers with Random numbers

    I'm glad I came back to visit this thread...tossing ideas around in my head while driving only came up with 'skewed' attempts. I wonder what this is for!!!!????

  23. #23

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: Fill x Numbers with Random numbers

    Quote Originally Posted by SamOscarBrown View Post
    I'm glad I came back to visit this thread...tossing ideas around in my head while driving only came up with 'skewed' attempts. I wonder what this is for!!!!????
    im sure this is useful in many situations; as for me, its to distribute some data 'evenly' to the (30 users)

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width