![]() |
|
[Java] How to make something happen randomly 'n' out of 'n' times? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] How to make something happen randomly 'n' out of 'n' times? (/showthread.php?tid=5543912) |
How to make something happen randomly 'n' out of 'n' times? - matt - Feb 5, 2017 It's a little embarrassing asking for help because I'm a pretty good programmer but unfortunately, I'm not that great at math, and so here's what I came up with. I know it's not the most efficient code so I would like to know if there's some other kind of alternative. :/ Code public static void main(String[] args) {* - Stealth™ - Feb 5, 2017 You'll have to explain exactly what you're trying to do. From the code that you've posted, I can't even decipher what your intentions are. Are you wanting something to happen at a certain % chance? * - matt - Feb 5, 2017 (Feb 5, 2017 03:41 PM)Stealth™ Wrote: You'll have to explain exactly what you're trying to do. From the code that you've posted, I can't even decipher what your intentions are. Are you wanting something to happen at a certain % chance? Yes pretty much, but I'm trying to represent it as a fraction. * - Stealth™ - Feb 5, 2017 (Feb 5, 2017 04:07 PM)Midnight Blue™ Wrote: Yes pretty much, but I'm trying to represent it as a fraction. You should always check StackOverflow before bothering to make a thread, any question you have was probably answered years ago :P http://stackoverflow.com/questions/11552158/percentage-chance-of-saying-something * - matt - Feb 5, 2017 (Feb 5, 2017 05:44 PM)Stealth™ Wrote: You should always check StackOverflow before bothering to make a thread, any question you have was probably answered years ago :P I've come across this topic already, but it's not quite what I'm trying to do. I have a numerator and a denominator and I want the numerator amount of rolls whilst the max value is the denominator and I want to refrain from changing it from a fraction to a percentage. * - Stealth™ - Feb 5, 2017 (Feb 5, 2017 06:17 PM)Midnight Blue™ Wrote: I've come across this topic already, but it's not quite what I'm trying to do. Any fraction can be represented as a percentage though. * - minimalist - Feb 5, 2017 Am I doing this wrong or is it not as trivial as you're making it out to be? Code int numerator = 1;* - matt - Feb 5, 2017 (Feb 5, 2017 07:16 PM)Minimalist Wrote: Am I doing this wrong or is it not as trivial as you're making it out to be? Damn that was so simple lol smh thanks man this works fine :-) I'm so dang bad at math my gosh |