こんにちは。
ほしかったので作ってみました。
なお、3時間半ほどで作ったので、バグとかがあるかもしれません。
その点を了承のうえ、お使いください。
----------
#module random
// 命令一覧
// rndInit p1, p2, p3
// 整数の乱数作成用の初期化処理
// p1:開始値
// p2:終了値
// p3:増減値
// 整数の乱数を取得するための準備をします。
// rndGet p1
// 乱数を取得
// p1:乱数生成のモードを指定
// 整数の乱数を取得します。
// p1を0にすると、作成されたすべての数字が対象となります。
// p1を1にすると、重複しないように乱数を作成します。
// rndInitD p1, p2, p3
// 小数の乱数の初期化処理
// パラメータはrndInitと同じ
// 小数の乱数を取得するための準備をします。
// rndGet p1
// 乱数を取得
// パラメータはrndGetと同じ
// 小数の乱数を取得します。
#deffunc rndInit int prm_1, int prm_2, int prm_3
if (prm_1>prm_2){
return -1
}
if (prm_3 = "" | prm_3 = 0){
return -2
}
notesel list
nowNum=prm_1
repeat
if (nowNum<=prm_2){
noteadd ""+nowNum
nowNum+prm_3
}else{
break
}
loop
max=notemax
noteunsel
return 0
#deffunc rndGet int prm_1
if (list = ""){
return "end"
}else{
notesel list
if (prm_1 = 0){
num=rnd(max)
noteget ret, num
ret=int(ret)
noteunsel
return ret
}else{
num=rnd(max)
noteget ret, num
ret=int(ret)
notedel num
max = max-1
noteunsel
return ret
}
}
#deffunc rndInitD double prm_1, double prm_2, double prm_3
if (prm_1>prm_2){
return -1
}
if (prm_3 = "" | prm_3 = 0){
return -2
}
notesel listD
nowNum=prm_1
repeat
if (nowNum<=prm_2){
noteadd ""+nowNum
nowNum+prm_3
}else{
break
}
loop
max=notemax
noteunsel
return 0
#deffunc rndGetD int prm_1, int prm_2
if (listD = ""){
return "end"
}else{
notesel listD
if (prm_1 = 0){
num=rnd(max)
noteget ret, num
ret=double(ret)
noteunsel
return ret
}else{
num=rnd(max)
noteget ret, num
ret=double(ret)
notedel num
max = max-1
noteunsel
return ret
}
}
#global
// サンプル
randomize
// サンプルその1:整数の乱数を取得して表示する
rndInit 1, 100, 1
if (stat = -1){
dialog "開始地が終了値よりも大きな値になっています。\n開始地を終了値より小さい値にして実行してください。", 1, "エラー"
}else : if (stat = -2){
dialog "増減値を指定してください。", 1, "エラー"
}else{
repeat 10
rndGet 0
if (refstr="end"){
dialog "範囲内の数字をすべて使い切りました。", 0, "終了"
}else{
dialog stat
}
loop
}
// サンプルその2:負の数を含む整数の乱数を取得して表示する、重複なしで乱数を取得
rndInit -50, 50, 1
if (stat = -1){
dialog "開始地が終了値よりも大きな値になっています。\n開始地を終了値より小さい値にして実行してください。", 1, "エラー"
}else : if (stat = -2){
dialog "増減値を指定してください。", 1, "エラー"
}else{
repeat 10
rndGet 1
if (refstr="end"){
dialog "範囲内の数字をすべて使い切りました。", 0, "終了"
}else{
dialog stat
}
loop
}
// サンプルその3:小数の乱数を取得して表示する、重複なしで乱数を取得
rndInitD 0.1, 2, 0.1
if (stat = -1){
dialog "開始地が終了値よりも大きな値になっています。\n開始地を終了値より小さい値にして実行してください。", 1, "エラー"
}else : if (stat = -2){
dialog "増減値を指定してください。", 1, "エラー"
}else{
repeat 10
rndGetD 1
if (refstr="end"){
dialog "範囲内の数字をすべて使い切りました。", 0, "終了"
}else{
dialog refdval
}
loop
}
end
----------
とりあえず、こんな感じでどうでしょうか。
参考になれば幸いです。