×
Namespaces

Variants
Actions
(Difference between revisions)

How to get a random number from range

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Tidy wiki text)
lpvalente (Talk | contribs)
m (Lpvalente -)
Line 7: Line 7:
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
+
|platform= Java ME
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->

Revision as of 03:11, 18 March 2012

This Java ME code snippet shows how to return a random number between a specified maximum and minimum value.

Article Metadata
Compatibility
Platform(s): Java ME
Article
Created: firt (15 Apr 2007)
Last edited: lpvalente (18 Mar 2012)
public int getRandomNumber(int min, int max) {
Random rnd;
rnd = new Random();
return min + rnd.nextInt(max - min);
}
109 page views in the last 30 days.