Random Class
The Random class generates random numbers.
Syntax
class Random extends Object
Run On
Called
Methods
Method | Description | |
---|---|---|
cancelTimeOut | Cancels a previous method call to the setTimeOut method. (Inherited from Object.) | |
equal | Determines whether the specified object is equal to the current one. (Inherited from Object.) | |
getTimeOutTimerHandle | Returns the timer handle for the object. (Inherited from Object.) | |
handle | Retrieves the handle of the class of the object. (Inherited from Object.) | |
new | Initializes a new instance of the Random class. (Overrides the new Method.) | |
nextInt | Returns the next random number from the random generator. | |
notify | Releases the hold on an object that has called the wait method on this object. (Inherited from Object.) | |
notifyAll | Releases a lock on the object that was issued by the wait method on this object. (Inherited from Object.) | |
objectOnServer | Determines whether the object is on a server. (Inherited from Object.) | |
owner | Returns the instance that owns the object. (Inherited from Object.) | |
setTimeOut | Sets up the scheduled execution of a specified method. (Inherited from Object.) | |
toString | Returns a string that represents the current object. (Inherited from Object.) | |
usageCount | Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.) | |
wait | Pauses a process. (Inherited from Object.) | |
xml | Returns an XML string that represents the current object. (Inherited from Object.) |
Top
Remarks
Because this class operates on a global random generator, the individual random objects will interfere with each other. Therefore, it is not possible to predict the sequence of numbers for a specific random object.
Examples
The following example prints 100 random numbers.
static void example()
{
Random myRand = new Random();
int i;
for(i=0;i<100;i++)
{
print myRand.nextInt();
}
}
Inheritance Hierarchy
Object Class
Random Class
RandomGenerate Class