I'm constructing an app and for that I have a function to fill it with test data. Short outline:
HashMap<String, Long> iIDs = new HashMap<String, Long>();
HashMap<String, Integer> vals = new HashMap<String, Integer>();
long iID1 = addIndicator("I1", "i1", Color.RED);
long iID2 = addIndicator("I2", "i2", Color.BLUE);
long iID3 = addIndicator("I3", "i3", Color.GREEN);
long iID4 = addIndicator("I4", "i4", Color.MAGENTA);
iIDs.put("iID1", iID1);
iIDs.put("iID2", iID2);
iIDs.put("iID3", iID3);
iIDs.put("iID4", iID4);
int v1 = 80;
int v2 = 30;
int v3 = 25;
int v4 = 40;
vals.put("v1", v1);
vals.put("v2", v2);
vals.put("v3", v3);
vals.put("v4", v4);
int numDays = 500;
int dateDistance = 14;
Calendar c = Calendar.getInstance();
for(int i=0;i<numDays;i++)
{
c.add(Calendar.DATE, dateDistance);
for(int j=1;j<5;j++)
{
int currVal = vals.get("v"+j);
int rand = new Random().nextInt(6);
int newVal;
if(rand <= 2) // 0, 1, 2
newVal = currVal + rand;
else // 3, 4, 5
newVal = currVal - rand;
pseudo: addPointForIndicator();
vals.put("v"+j, newVal);
}
}
No matter how often I create the test data, the picture looks always like this:
So the trend of the random numbers is always negative. Why is that?
Random
object in each loop iteration? – RoachRandom
is wrong. You must share the same instance across all calls, otherwise you are not getting a pseudorandom sequence. – Guerrerojava.util.Random
for generation of all random numbers. This will "increase randomization" by making the randomization true pseudo-randomization. – Chemosphere