How to generate 100 random numbers, sum to 1000 and I can set the dispersion of these 100 data, and run in the experimenter or optimizer?
How to generate 100 random numbers, sum to 1000 and I can set the dispersion of these 100 data, and run in the experimenter or optimizer?
Generate 1000 values with a statistical distribution of your choice with a mean value of 10, saving them in an array or table.
Sum the numbers up to get the offset to your target sum of 1000. Adjust each number proportionally by that offset (for example decrease each value by 0.2% if your sum is 1002).
Create a parameter that controls which of the values will be accessed during a simulation run. So the parameter would either represent the index of the array or the row of the table.
For integers you could use something like this:
Array integers=Array(100); for (int n=1000;n>0;n--) integers[duniform(1,100)]++; // (add a stream for repeatability) return integers;
Thank you, how to set the dispersion of these 100 data
You could affect the value spread by altering the index generation ( a custom distribution rather than uniform). Then you can randomly resequence the array if needed.
int numValues=100; Array integers=Array(numValues); for (int n=1000;n>0;n--){ int idx=Math.min(Math.max(1,normal(numValues/2,numValues/5)),numValues); integers[idx]++; } Array result; while (integers.length) result.splice(duniform(1,result.length),0,integers.pop()); return result;
Here's a simple code that generates 100 values from a normal distribution that sum to 1000 and writes them to a column in a global table.
Table destTable = Table("GlobalTable1");
int col = 1; int numValues = 100; double targetSum = 1000; double mean = targetSum/numValues; double stdDevFactor = 0.2; double stdDev = mean*stdDevFactor; destTable.setSize(Math.max(numValues, destTable.numRows), Math.max(col, destTable.numCols)); Array values = []; double sum = 0; for(int i = 1; i <= numValues; i++) { double value = normal(mean, stdDev, realtime(1)); sum += value; values.push(value); } double offsetFactor = sum/targetSum; for(int i = 1; i <= values.length; i++) { destTable[i][col] = values[i]/offsetFactor; }
Since I don't know how you plan to use those numbers, I can't provide any inside into how to proceed from there.
15 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved