Howdy, Stranger!

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


I was wondering how can I generate a random number?

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


  • KyonKyon Member Posts: 113

    Take a look at the API:


    -- 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, ...

    import java.util.Random;
    Random random = new Random();

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

    : Top. Does Java include a random number function.

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

    _____ || || 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.