i=50 ;i個の違う数を出す
dim test,i ;変数の定義
repeat i ;ランダムでi個の数字を出したい
e=cnt ;次のrepeatでcntに別の数字が代入されるため
*rnds
z=0
rnd r,100 ;ランダムで0〜99の数字をrに代入
test.e=r
repeat e+1 ;以前に同じ数字があったか調べるrepeat文
if ((test.cnt=test.e)&(e!=cnt)){z=1:break} ;同じ数字があったら*rndsへ戻る
loop
if z=1 : goto *rnds
print "no."+e+"="+test.e ;表示する
loop
以上によりtest.0〜test.49に0〜99の数が重複なく代入されます。
test.e=r+100 とすれば 100〜199の数が重複なく代入されます。
目次へ 前へ 次へ
|