MathematicaFor[k = 0,k < 10,k++,income = 0;For [i = 0 ,i < 1000,i++,list = RandomSample[{10,10,10,10,10,10,10,10,10,10,5,5,5,5,5,5,5,5,5,5},10]; (这个是无重复选取)S = Sum[j,{j,list}];If[S == 50 || S == 100,income -= 100,If[S == 55 || S == 95,
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 15:34:24
MathematicaFor[k = 0,k < 10,k++,income = 0;For [i = 0 ,i < 1000,i++,list = RandomSample[{10,10,10,10,10,10,10,10,10,10,5,5,5,5,5,5,5,5,5,5},10]; (这个是无重复选取)S = Sum[j,{j,list}];If[S == 50 || S == 100,income -= 100,If[S == 55 || S == 95,
Mathematica
For[k = 0,k < 10,k++,
income = 0;
For [i = 0 ,i < 1000,i++,
list = RandomSample[{10,10,10,10,10,10,10,10,10,10,5,5,
5,5,5,5,5,5,5,5},10]; (这个是无重复选取)
S = Sum[j,{j,list}];
If[S == 50 || S == 100,income -= 100,
If[S == 55 || S == 95,income -= 10,
If [S == 70 || S == 75 || S == 80,income += 1];
]
]
]
Print[income];
]
你之前回答的问题写的代码 为什么我用Mathematica 运行后是全为0呢?我是用5.0的版本 还有我不懂你中间 list = RandomSample[{10,10,10,10,10,10,10,10,10,10,5,5,
5,5,5,5,5,5,5,5},10];这句代码的意思
MathematicaFor[k = 0,k < 10,k++,income = 0;For [i = 0 ,i < 1000,i++,list = RandomSample[{10,10,10,10,10,10,10,10,10,10,5,5,5,5,5,5,5,5,5,5},10]; (这个是无重复选取)S = Sum[j,{j,list}];If[S == 50 || S == 100,income -= 100,If[S == 55 || S == 95,
关于随机数的函数,5.0中只有一个Random.RandomSample是6.0版才增加的函数.
不会吧?会不会是5.0中没有这个语句啊。。 RandomSample[{a},b] 就是返回从数组a中无放回地取出10个元素,返回一个数组,赋值给list