Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I was wondering how can I generate a random number?

HGeneAnthonyHGeneAnthony Member Posts: 92
Top. Does Java include a random number function.

Comments

  • KyonKyon Member Posts: 113
    Hi.

    Take a look at the API:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Math.html#random()

    Cheers,
    Kyon

    -- planning is the substitution of hazard by error --

  • Feanors CurseFeanors Curse Member Posts: 70
    Yes, it has. You have to import java.util.Random; Then you make an instance of [italic]Random[/italic] and use it's function, for example [italic]nextInt[/italic]. There are also function for boolean, ...

    [code]
    import java.util.Random;
    ...
    Random random = new Random();

    // create random number between 0 and 4
    int i = random.nextInt(5);
    [/code]

    : Top. Does Java include a random number function.
    :

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _____ || http://forcoder.org || free video tutorials and ebooks about ( PHP C Swift Ruby Objective-C JavaScript C++ Perl Go Assembly Delphi Python C# MATLAB Visual Basic .NET PL/SQL Java R Visual Basic Scratch Scala Prolog VBScript Rust LabVIEW Erlang Julia F# Ada Logo ML Kotlin ABAP Bash FoxPro Alice SAS COBOL Fortran Lua D Hack Apex Transact-SQL Awk Clojure Scheme Lisp Dart Crystal ) _____________

Sign In or Register to comment.