Randomクラス

Randomクラスは、double型,float型,int型,long型の乱数を生成するために使用します。

Randomコンストラクタ

#codeprettify{{ random() random( long seed ) }}

引数説明
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
Last-modified: 2013-03-12 (火) 09:16:56