https://github.com/sinipelto/probabilitycalculator
Calculates true or false (meaning event happens or not happens) with given probability of 1/n where n is user input.
https://github.com/sinipelto/probabilitycalculator
Last synced: 9 days ago
JSON representation
Calculates true or false (meaning event happens or not happens) with given probability of 1/n where n is user input.
- Host: GitHub
- URL: https://github.com/sinipelto/probabilitycalculator
- Owner: sinipelto
- License: gpl-3.0
- Created: 2018-03-31T22:24:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-01T11:27:02.000Z (over 8 years ago)
- Last Synced: 2025-06-15T18:56:35.140Z (about 1 year ago)
- Language: C++
- Size: 21.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# probabilityCalculator
Calculates true or false (meaning event happens or not happens) with given probability of 1/n where n is user input.
Function probability(unsigned const n):
Input n is the factor of the probability to use with a simple formula 1/n. For example, if n = 100, function will calculate
true or false with probability 1/100 (which means a probability of 0.01 (1%). Any value that is >= 0 and <= INT_MAX may be used.
Function generates 2 random unsigned integers between 1 and n and compares them with each other. If they do match, then the event
does happen (it's true, returns true), otherwise it doesn't (it's false, returns false).
In the main function is a user interface to use this function more easily. The UI is also very easy to expand with more
commands if necessary.