Answers for "java random 1 to 7"

1

java random number between 1 and 10

/* First Method */
int random = (int) (Math.random() * 100 + 1); /* Random number between 1 and 100*/
int random = (int) (Math.random() * 65 + 1); /* Random number between 1 and 65*/
/* Second Method */
import java.util.Random;
Random randnumber = new Random();
int number = randnumber.nextInt(100); /* between 1 and 100*/
system.out.println(number);
Posted by: Guest on June-17-2021
0

java random number generator 3

int[] state;
// Iterate through the state
for (i = 0; i < 624; i++) {
  // y is the first bit of the current number,
  // and the last 31 bits of the next number
  int y = (state[i] & 0x80000000) + (state[(i + 1) % 624] & 0x7fffffff);
  // first bitshift y by 1 to the right
  int next = y >>> 1;
  // xor it with the 397th next number
  next ^= state[(i + 397) % 624];
  // if y is odd, xor with magic number
  if ((y & 1L) == 1L) {
    next ^= 0x9908b0df;
  }
  // now we have the result
  state[i] = next;
}
Posted by: Guest on October-16-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language