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?

Continue Learning about Math & Arithmetic
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); }


The greatest integer function shown below is defined so that it produces the greatest integer or equal to x.?

The greatest integer function, often denoted as (\lfloor x \rfloor), returns the largest integer that is less than or equal to the given value (x). For example, (\lfloor 3.7 \rfloor) equals 3, while (\lfloor -2.3 \rfloor) equals -3. This function effectively &quot;rounds down&quot; any non-integer value to the nearest whole number.


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 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.


What does the DIVSUM function does?

The DIVSUM function calculates the sum of the divisors of a given integer, excluding the integer itself. For example, for the input 12, the function would return the sum of its divisors 1, 2, 3, 4, and 6, which equals 16. This function is often used in number theory and can help identify perfect numbers, abundant numbers, and deficient numbers based on the sum of their divisors.


What is an expression for 'the next integer'?

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


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.