Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

How to add negative random numbers in java


//To get a random number between a set range with min and max:

int number = random.nextInt(max - min) + min;
//It also works with negative numbers.

//So:

random.nextInt(30 + 10) - 10;
// max = 30; min = -10;
//Will yield a random int between -10 and 30 (exclusive).

//It also works with doubles.
Comment

PREVIOUS NEXT
Code Example
Java :: android plain text remove underline 
Java :: java create date object from yesterday 
Java :: big screen jframe 
Java :: how to make jframe visible 
Java :: keytool error: java.lang.Exception: Keystore file does not exist: ~/.android/debug.keystore 
Java :: java double to fixed decimal 
Java :: java read last line of file 
Java :: java double to string with 2 decimals 
Java :: simple yes no dialog android default java 
Java :: list of longs to comma separeated string java 
Java :: admost track purchase 
Java :: java for each array 
Java :: How to efficiently count the number of smaller elements to the right of every array element, in Java? 
Java :: wat is voorbereiden voltooid deelwoord 
Java :: similarity between abstract class and interface java 
Java :: fizzbuzz java 
Java :: append to file in java 
Java :: spring serve robots.txt 
Java :: How to iterate over a list in Java? 
Java :: Not supported for DML operations 
Java :: taking string input in java 
Java :: show confirmation dialog java android 
Java :: how to add a keylistener to a jframe 
Java :: print line number java 
Java :: main method in java without static keyword 
Java :: close scanner java 
Java :: java swing enter key press event 
Java :: java eliminate numbers from string 
Java :: how to reverse a list in java 
Java :: java toast 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =