bchip
Expert Member
- Joined
- Mar 12, 2013
- Messages
- 1,324
- Reaction score
- 418
I'm currently coding something that does the following:
List of numbers: 10, -20, 15, -5, 10 (start with 5)
Shuffle the numbers and see how many of these dip below 10 (then stop)
So possible outcomes are
1) 5 -> 10-20, stop = -5
2) 5 -> -20,stop = -15
3) 5 -> 10+10+15-20 = 15 (all got through)
etc
All the values -5, -15, 15... are capture in a List<double>
When I run the code in debug mode with a watch I get random outcomes
When I run the code without debug mode I would get -5,-5,-5,-5 (same number over and over)
To have the same number over and over is really impossible.
I think it has to do with it the timing issue in the for loop with the the time it took to save it to a List
Anyone got any ideas on this?
List of numbers: 10, -20, 15, -5, 10 (start with 5)
Shuffle the numbers and see how many of these dip below 10 (then stop)
So possible outcomes are
1) 5 -> 10-20, stop = -5
2) 5 -> -20,stop = -15
3) 5 -> 10+10+15-20 = 15 (all got through)
etc
All the values -5, -15, 15... are capture in a List<double>
When I run the code in debug mode with a watch I get random outcomes
When I run the code without debug mode I would get -5,-5,-5,-5 (same number over and over)
To have the same number over and over is really impossible.
I think it has to do with it the timing issue in the for loop with the the time it took to save it to a List
Anyone got any ideas on this?
Code:
double ftotal = 0;
List<double> nList = GroupList.Shuffle(theList);
for (int tcnt = 0; tcnt < nList.Count; tcnt++)
{
if (!isRuined)
{
if (ftotal < minallwd)
{
isRuined = true;
ncontracts = 0;
}
}
ftotal += (nList[tcnt] * ncontracts);
}
capList.Add(ftotal);