I have to generate two random sets of matrices Each containing 3 digit numbers ranging from 2 - 10
like that
matrix 1: 994,878,129,121
matrix 2: 272,794,378,212
the numbers in both matrices have to be greater then 100 and less then 999
BUT
the mean for both matrices has to be in the ratio of 1:2 or 2:3 what ever constraint the user inputs
my math skills are kind of limited so any ideas how do i make this happen?
-
In order to do this, you have to know how many numbers are in each list. I'm assuming from your example that there are four numbers in each.
- Fill the first list with four random numbers.
- Calculate the mean of the first list.
- Multiply the mean by 2 or by 3/2, whichever the user input. This is the required mean of the second list.
- Multiply by 4. This is the required total of the second list.
- Generate 3 random numbers.
- Subtract the total of the three numbers in step 5 from the total in step 4. This is the fourth number for the second list.
- If the number in step 6 is not in the correct range, start over from step 5.
Note that the last number in the second list is not truly random, since it's based on the other values in the list.
: makes sense let me try that thanks a million!!: I tried the solution but its almost impossible to get the right value the program keeps on looping expectedTotal: 4322 second matrix: 537,178,569 Sum of the matrix : 1284 fourth number: 3038 is there something i am missingBill the Lizard : How are you seeding the random number generator?: first matrix 100- 499 second 100-999Bill the Lizard : I mean, what are you using to get random numbers? Like, in Java, you'd use Random rand = new Random();, then use rand.nextInt(1000);. How are you doing that? -
You have a set of random numbers, s1.
s1= [ random.randint(100,999) for i in range(n) ]
For some other set, s2, to have a different mean it's simply got to have a different range. Either you select values randomly from a different range, or you filter random values to get a different range.
No matter how many random numbers you select from the range 100 to 999, the mean is always just about 550. The odds of being a different value are exactly the normal distribution probabilities on either side of the mean.
You can't have a radically different mean with values selected from the same range.
: range has to be the same, the mean has to be different.Brent.Longborough : Sorry, but if the range is the same, and the numbers are truly random, the expected value of the mean will be the same. Pick any two from (same range, random, different means).S.Lott : @Brent Longborough: The original question is either misstated or is a logical contradiction.
0 comments:
Post a Comment