answersLogoWhite

0

import java.util.Random;

public class Test

{

static int rand7() {

int i;

int max;

i = 5 * rand5() + rand5();

max = 25;

while(i < max%7) {

i *= 5;

i += rand5();

max %= 7;

max *= 5;

}

return(i%7);

}

private static int rand5()

{

Random rand = new Random() ;

int min = 1;

int max = 5;

int randomNum = rand.nextInt(max - min + 1) + min;

return randomNum;

}

public static void main(String [] args)

{

System.out.println(rand7());

}

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7?

In C, one possible solution: int rnd7 () { int i, r; r = 0; for (i = 0; i &lt; 9; i++) r += rnd5() - 1; return 1 + (r % 7); }


For a continuous random variable the probability that the value of x is greater than a given constant is?

The integral of the density function from the given point upwards.


Given the prime factorization of an integer how can you determine if our integer is a perfect square?

Given the prime factorization of an integer how can you determine if our integer is a perfect square?


What is probability distibution?

A statistical function that describes all the possible values and likelihoods that a random variable can take within a given range.


What is the correlation function?

A random galaxy is used in the "Correlation function" [See Link] to describe the possibilities of another galaxy being found within a certain distance.Given a random galaxy in a location, the correlation function describes the probability that another galaxy will be found within a given distance.See related for types of galaxies.


What is an expression for 'the next integer'?

If your integer is "n", then the next integer will be "n+1".


What is the meaning of random variable in probability distribution?

It is a variable that can take a number of different values. The probability that it takes a value in any given range is determined by a random process and the value of that probability is given by the probability distribution function.It is a variable that can take a number of different values. The probability that it takes a value in any given range is determined by a random process and the value of that probability is given by the probability distribution function.It is a variable that can take a number of different values. The probability that it takes a value in any given range is determined by a random process and the value of that probability is given by the probability distribution function.It is a variable that can take a number of different values. The probability that it takes a value in any given range is determined by a random process and the value of that probability is given by the probability distribution function.


How do you make 0.6666667 an integer?

The given number is a fraction. It cannot be made into an integer.


What is the product of a given whole number and an integer?

It is a whole number which is another name for an integer.


What number is the product of a given number and an integer?

An integral multiple of the given number.


How do you find by program a given number is integer or float?

If it contains a decimal point or an exponential part, then it should be handled as a float (or double).You can determine an existing variable's type in C using the type() function


Digits of a given integer are equal or not?

More often they are not.