×
Namespaces

Variants
Actions
(Difference between revisions)

Como obter um número aleatório em Java ME

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot addition of Template:ArticleMetaData)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update of Template:ArticleMetaData)
Line 12: Line 12:
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|language=Lang-Portuguese
 
|language=Lang-Portuguese
|translated-by= <!-- [[User: XXXXX]] -->
+
|translated-by=[[User:Maiconherverton]]
|translated-from-title=<!-- Title only -->
+
|translated-from-title=How to get a random number from range
|translated-from-id= <!-- Id of translated revision -->
+
|translated-from-id=51213
 
|review-by=<!-- After re-review: [[User:username]] -->
 
|review-by=<!-- After re-review: [[User:username]] -->
 
|review-timestamp=<!-- After re-review: YYYYMMDD -->
 
|review-timestamp=<!-- After re-review: YYYYMMDD -->
Line 20: Line 20:
 
|update-timestamp=<!-- After significant update: YYYYMMDD -->
 
|update-timestamp=<!-- After significant update: YYYYMMDD -->
 
|creationdate=20090911
 
|creationdate=20090911
|author=[[User:Maiconherverton]]
+
|author=[[User:Firt]]
 
}}[[Category:Java ME]][[Category:Lang-Portuguese]][[Category:Code Examples]]
 
}}[[Category:Java ME]][[Category:Lang-Portuguese]][[Category:Code Examples]]
  
Line 36: Line 36:
 
}
 
}
 
</code>
 
</code>
 +
<!-- Translation --> [[en:How to get a random number from range]]

Revision as of 08:35, 7 December 2011

Article Metadata

Artigo
Tradução:
Por maiconherverton
Última alteração feita por hamishwillee em 07 Dec 2011

Original: How to get a random number from range (Inglês)

Se você precisa obter um número aleatório entre X e Y, você deve usar algum padrão matemático usando a classe Math e alguns cálculos.

Você pode usar esse método para obter rapidamente o número aleatório:

public int getRandomNumber(int min, int max) {
Random rnd;
rnd = new Random();
return min + Math.abs(rnd.nextInt()) % (max - min);
}
97 page views in the last 30 days.
×