标签:local blog dom math while mat end 全排列 rand
n = 0 function () local n = n + 1 while n < 100 do math.random(100) end end
随机乘以1到100以内的数↑
全排列,可以产生N!种排列:
local N = 100 local array = {} for i = 1 , N do array[i] = i end for i = 1 , N do local j = math.random(N - i + 1) + i - 1; array[i],array[j] = array[j],array[i] end for i = 1 , N do print(array[i]) end
从1加到100:
i = 1; sum = 0; while (i<=100) do sum = sum + i i = i + 1 end print (sum)
简算式:
sum = 100 * (100-1)/2
标签:local blog dom math while mat end 全排列 rand
原文地址:http://www.cnblogs.com/tgsslzt/p/6610924.html