我正在构建一个应用程序,为此我有一个用测试数据填充它的功能。简短的大纲:
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);
}
}
无论我多久创建一次测试数据,图片看起来总是这样:
所以随机数的趋势总是负的。这是为什么?