Posted By: Anonymous
The first solution is to use the
import java.util.Random; Random rand = new Random(); // Obtain a number between [0 - 49]. int n = rand.nextInt(50); // Add 1 to the result to get a number from the required range // (i.e., [1 - 50]). n += 1;
Another solution is using
double random = Math.random() * 49 + 1;
int random = (int)(Math.random() * 50 + 1);
Answered By: Anonymous
- How to generate a random string of a fixed length in Go?
- How can I resolve Web Component Testing error?
- Dynamically update values of a chartjs chart
- Examples of GoF Design Patterns in Java's core libraries
- How to generate a random number in C++?
- 'foo' was not declared in this scope c++
- How to re-size polygon in jPanel?
- Changes do not get reflected when getting property by name
- Why are elementwise additions much faster in…
- Generating a random & unique 8 character string…
- Finding all possible combinations of numbers to…
- How to get a random number in Ruby
- Simple Random Samples from a Sql database
- Fastest way to iterate over all the chars in a String
- Delete a row in Excel VBA
- Calculating distance between two points, using…
- Math.random() explanation
- Auto-fit TextView for Android
- Generating random strings with T-SQL
- How to calculate distance between two locations…
- C compile error: Id returned 1 exit status
- How do I copy a range of formula values and paste…
- Matching input value with an element in array each…
- java.lang.ClassNotFoundException: HttpServletRequest
- Passing an array value from one class to another
- How do I generate a random integer between min and…
- Unexpected end of JSON input while parsing
- Excel VBA For Each Worksheet Loop
- how do I replace a static array with a dynamic one?
- How to avoid using Select in Excel VBA
- How to read strings from a Scanner in a Java console…
- Improved way to get subsets of a list
- SecurityException: Permission denied (missing…
- CUDA: Pass device function as an argument to global function
- Output not incrementing correctly - C++
- Excel VBA: AutoFill Multiple Cells with Formulas
- Java adding objects according to ratios and population sizes
- Program.Mattor(): not all code paths return a value.…
- How to generate JAXB classes from XSD?
- Item position in RecyclerView only changing when…
- How to create range in Swift?
- How do I get the overall maximum value in a 2d array?
- How to generate a random integer number from within a range
- Java error - "invalid method declaration; return…
- Scanner is skipping nextLine() after using next() or…
- android studio 0.4.2: Gradle project sync failed error
- Launching Spring application Address already in use
- Could not install Gradle distribution from…
- Random normal distribution generator comparison
- How to loop through a column to copy all matching…
- Basic calculator in Java
- How to convert java.util.Date to java.sql.Date?
- Palindromic numbers in Java
- Random float number generation
- Adding asterisk to required fields in Bootstrap 3
- What does the Excel range.Rows property really do?
- Sorting 1 million 8-decimal-digit numbers with 1 MB of RAM
- Creating random colour in Java?
- How to draw interactive Polyline on route google…
- Is there a reason why it doesn't go to the 'else if'…
- Drawing a simple line graph in Java
- Multidimensional Array  vs [,]
- Print series of prime numbers in python
- Using scanner.nextLine()
- 'int' object has no attribute '__getitem__'
- Generating Unique Random Numbers in Java
- There's an InputMismatchException, how do i fix it?
- Eclipse will not start and I haven't changed anything
- Retain precision with double in Java
- Math.random() versus Random.nextInt(int)
- Android setOnClickListener method - How does it work?
- Is there a more efficient way to divide and conquer…
- How to concatenate cell values until it finds a…
- Creating random numbers with no duplicates
- Tomcat 7 "SEVERE: A child container failed during start"
- Why is "1000000000000000 in range(1000000000000001)"…
- Callback functions in C++
- How to change the range slider addition by click on…
- Generate random numbers uniformly over an entire range
- Add JsonArray to JsonObject
- Why am I getting InputMismatchException?
- How to obtain the start time and end time of a day?
- How to use AVX instructions to optimize ReLU written in C
- Exception in thread "JobGenerator"…
- How to format a phone number in a textfield
- How do I generate random number for each row in a…
- tkinter: how to use after method
- Why do I always get the same sequence of random…
- cannot make a static reference to the non-static field
- Neither BindingResult nor plain target object for…
- No Such Element Exception?
- How to resolve "Could not find schema information…
- Java program to find the largest & smallest…
- Find distance between two points on map using Google…
- Fill an array with random numbers