Timeline for C++ Int Array/Vector Over 100 Million
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 8, 2015 at 3:53 | history | edited | Mat | CC BY-SA 3.0 |
added 2 characters in body
|
Sep 8, 2015 at 3:51 | comment | added | Mat |
Missing a pair of parens, that will indeed overflow. Fix is freq*(rolls/36.0) otherwise the result of the multiplication (overflow here) is divided by 36. I'm using GCC and clang, both give about the same timings.
|
|
Sep 8, 2015 at 3:08 | comment | added | Austin |
Curious to what compiler/settings you are using. The above takes me about 3 min with VS2015 (default). Also over a billion throws frequency[i] * std::max(36, rolls) / 36.0; will return negative sometimes; consistently for the odds of rolling a 7. Might be just me?
|
|
Sep 7, 2015 at 4:01 | vote | accept | Austin | ||
Sep 7, 2015 at 3:49 | history | edited | Mat | CC BY-SA 3.0 |
added 6 characters in body
|
Sep 7, 2015 at 3:44 | comment | added | Mat |
You've described it well. So counts[n] represents the number of times you got n as the sum of a two-dice throw. Looks like you found a bug in my code :-) I'm not initializing the counts array and got away with it in my tests... Fix it up with int counts[13] = {0} .
|
|
Sep 7, 2015 at 1:26 | comment | added | Austin |
Overall this was great advice, thank you it's greatly appreciated. Though, I am having trouble understanding counts[dis(gen) + dis(gen)]++; . I understand dis(gen) is an int ranging from 1 to 6, and when summed will effectively give a value for that instance of a roll. But why are you using that for an index of counts and then incrementing it? Is this meant to provide the frequency at which that sum occurred? The above code, along with what I have modified of my own returns numbers in the -858993### range; skewing other calculations.
|
|
Sep 6, 2015 at 13:39 | history | edited | Mat | CC BY-SA 3.0 |
Revised modified code, still not really sure about naming...
|
Sep 6, 2015 at 12:40 | history | edited | Mat | CC BY-SA 3.0 |
added 1943 characters in body
|
Sep 6, 2015 at 12:35 | history | edited | Mat | CC BY-SA 3.0 |
added 1943 characters in body
|
Sep 6, 2015 at 12:01 | history | answered | Mat | CC BY-SA 3.0 |