www.pudn.com > MobiCraft_src.rar > MyRandom.java
// style: tabs, tabsize=4, style=ANSI
//+----------------------------------------------------------------------+
// Copyleft 2007. MobiCraft Team. GNU GPL license.
// Made by Andrew Denisov and Zahar Semenov
//+----------------------------------------------------------------------+
// Filename: MyRandom.java
//+----------------------------------------------------------------------+
// Comment: To have normal random on CLDC 1.0 and MIDP 2.0
//+----------------------------------------------------------------------+
package app;
import java.util.Random;
public class MyRandom
{
private Random mRandom;
public MyRandom()
{
mRandom = new Random();
mRandom.setSeed(System.currentTimeMillis());
}
// Возвращает значение от 0 до i-1
public int Rand (int i)
{
int temp = 0;
do
{
temp = Math.abs(mRandom.nextInt()) % (i + 1);
}
while (temp == 0); // Иначе ноль более вероятен.
return (temp - 1);
}
}