Link to home
Start Free TrialLog in
Avatar of Annje Tref
Annje Tref

asked on

nextBoolean(double p) for Random class

I need to create a method using Random class which would return true with specified odds. I tried using a loop but it returns true all the time?
Here it is:

public boolean nextBoolean(double p) {
	double n = rgen.nextDouble()*(p+0.1) ;
	for (double i= 0.0; i <= n;) {
		return true;
	}
	
  return false;

Open in new window

SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Annje Tref
Annje Tref

ASKER

@dpearson yes exactly, thanks !