Generando un número aleatorio
public int getRandomNumber(int min, int max) {
return (int) ((Math.random() * (max - min)) + min);
}
Amused Alligator
public int getRandomNumber(int min, int max) {
return (int) ((Math.random() * (max - min)) + min);
}
function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// C program to generate random numbers
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
// Driver program
int main(void)
{
// This program will create different sequence of
// random numbers on every program run
// Use current time as seed for random generator
srand(time(0));
for(int i = 0; i<4; i++)
printf(" %d ", rand());
return 0;
}
import random # Import random libary
minimum = 1 # Minimum number
maximum = 10 # Maximum number
random_number = random.randint(minimum,maximum) # Generate random number
print(random_number) # Print random number
System.out.println(Math.random());