#navi(開発メモ/Java/基礎);
*Randomクラス [#qcfb85e5]
Randomクラスは、double型,float型,int型,long型の乱数を生成するために使用します。~

''Randomコンストラクタ''
#codeprettify{{
random()
random( long seed )
}}

|引数|説明|h
|seed|乱数ジェネレータに引き渡す初期値|

最初のコンストラクタでは時刻をseedに使用します。~

''例''
#codeprettify{{
import java.util.*;

class randomInts{
    public static void main(String args[]){
        //乱数ジェネレータを作成する
        Random generator = new Random();
        //10個のint型の乱数を生成する
        for (int i= 0; i < 10; i++){
            System.out.println(generator.nextInt());
        }
    }
}
}}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS