|
But I would be interested in the performance implications.
steve d.
set = require "set" function count(s) local n=0 for k in pairs(s) do n=n+1 end return n end function ranset(N,m) local s if arg[1]=='s' then s=set{} else s={}; setmetatable(s,{__unm=count}) end for k=1,N do s[math.random(m)]=1 end return s end maxit=1000 size=1000 limit=2000 ave=0 for iter=1,maxit do s=ranset(size,limit); ave=ave+(-s) end print ("average set size = ",ave/maxit)