random.nextInt(33) 随机产生一个大于等于0,小于33的整数
示例: 双色球 twocolorball.groovy
import java.util.Random;
int a =0;
int b =0;
def random = new Random();
def reds = [];
while(reds.size() <6){
a = random.nextInt(33)+1;
if(! reds.contains(a)) reds.add(a);
}
println "红球: ${reds.sort()}"
b = random.nextInt(16)+1;
print "蓝球: ${b}"
运行 groovy twocolorball
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/belldeep/article/details/47059777