This documentation is archived and is not being maintained.

Random.nextFloat Method

Visual Studio 2005

Generates a random float value between 0 and 1.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public float nextFloat();

A random float value between 0 and 1.

The following example prints out 10 random float values.

// random_nextfloat.jsl

import java.util.*;

public class Program
{
    public static void main(String[] args)
    {
        // Get the current time.
        Date date = new Date();
        long time = date.getTime();

        // Initialize the random number generator using the
        // time from above.
        Random r = new Random(time);

        // Generate 10 random floats.
        for (int i = 0; i < 10; i++)
        {
            System.out.println(r.nextFloat());
        }
    }
}

/*
Output:
0.6807229
0.271337152
0.0456498861
0.424616158
0.145857215
0.313717842
0.793788552
0.0299280882
0.9014773
0.0284169316
*/
Show: