I'm trying to come up with some code that will run a given pecentage of the time. In other words I want say a 15% chance that a certian branch will be taken. This is what I have come up with so far, but I'm wondering is there a cleaner solution.
[ June 06, 2005: Message edited by: Bob Beerbower ]
Regards Bob Beerbower
Joined: Jan 29, 2003
Looks like something I've done in other languages, so I'd call it a fine way to go. I'd think about the variable name ... it holds a random number between 1 and 100 ... is fifteenPercent descriptive?
If you have a 15% chance of branch A and a 30% chance of B you can elaborate like this:
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Oct 24, 2000
You can save some cycles by not casting to int and not adding 1:
Consultant to SCJP team.<br />Co-designer of SCJD exam.<br />Co-author of "Complete Java 2 Certification Study Guide".<br />Author of "Ground-Up Java".
Joined: Jun 06, 2001
Originally posted by Philip Heller: You can save some cycles by not casting to int and not adding 1:
Perfect, just what I was looking for. I new I was over complicating this.