zoukankan      html  css  js  c++  java
  • lua随机数

    function getrandom(nMax)
    	math.randomseed(tostring(os.time()):reverse():sub(1, 6))
    	local tab = {}
    	local tabFin = {}
    	local Rand
    	for i=1,nMax do
    		table.insert(tab,i)
    	end
    	for i=1,table.getn(tab) do
    		Rand = math.random(table.getn(tab))
    		while tab[Rand] == nil do
    			Rand = math.random(table.getn(tab))
    		end
    		table.insert(tabFin,tab[Rand])
    		table.remove(tab,Rand)
    	end
    	return tabFin
    end
    
    local testrand = getrandom(10)
    for k,v in pairs(testrand) do
    	print(k,v)
    end
    

     

    function getrandom(nMin,nMax)
    	math.randomseed(tostring(os.time()):reverse():sub(1, 6))
    	local tab = {}
    	local tabFin = {}
    	local Rand
    	for i=1,nMax do
    		table.insert(tab,i)
    	end
    	for i=1,table.getn(tab) do
    		Rand = math.random(table.getn(tab))
    		while tab[Rand] == nil do
    			Rand = math.random(table.getn(tab))
    		end
    		table.insert(tabFin,tab[Rand])
    	end
    	Rand = math.random(table.getn(tab))
    	while tab[Rand] == nil do
    		Rand = math.random(table.getn(tab))
    	end
    	table.remove(tab,Rand)
    	return (tabFin[Rand]+nMin-1)
    end
    print(getrandom(1,10))
    

      

  • 相关阅读:
    模板类 & 虚函数
    Page Color (页面着色)
    修改静态库
    ElementUI 时间选择器
    自定义export
    vue组件
    ElementUI 表格
    ElementUI 分页
    数组方法分类
    Vue过滤数组副本
  • 原文地址:https://www.cnblogs.com/byfei/p/2932074.html
Copyright © 2011-2022 走看看