Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --True Random API for Minecraft mod ComputerCraft
- --By minimite
- --For future notice, do NOT run this program manually (os.loadAPI is fine), or else a reboot is needed.
- local header = {
- ["User-Agent"] = "I'll leave the user-agent as this."
- }
- function getQuota(ip)
- local ip = ip or nil
- if ip then
- local rand = http.get("http://www.random.org/quota?ip="..ip.."&format=plain", header)
- local result = rand.readAll()
- local result = tonumber(result)
- return result
- else
- local rand = http.get("http://www.random.org/quota?format=plain", header)
- local result = rand.readAll()
- local result = tonumber(result)
- return result
- end
- end
- function quotaCheck() --Used to make sure clients don't ban themselves from random.org by using negative quota
- local quota = tonumber(getQuota())
- if quota < 1 then
- error("Sorry, but you've used all of your quota! If you wonder what Quota is, it's to make sure people don't hog all the random requests, and I have installed this to ensure your IP doesn't ban itself from using negative quota. Come back tommorow to issue MAOR random requests!")
- end
- end
- function number(min,max,amount)
- quotaCheck()
- local amount = amount or 1
- local min = min or 1
- local max = max or 10
- local rand = http.get("http://www.random.org/integers/?num="..amount.."&min="..min.."&max="..max.."&col=1&base=10&format=plain&rnd=new",header)
- local result = rand.readAll()
- return result
- end
- function string(length,amount)
- quotaCheck()
- local amount = amount or 1
- local length = length or 8
- local rand = http.get("http://www.random.org/strings/?num="..amount.."&len="..length.."&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new", header)
- local result = rand.readAll()
- return result
- end
- function ticket(amount)
- quotaCheck()
- local amount = amount or 1
- local rand = http.get("http://www.random.org/quick-pick/?tickets="..amount.."&lottery=5x59.1x35&format=plain", header)
- local result = rand.readAll()
- return result
- end
- function byte(length,type)
- quotaCheck()
- local length = length or 10
- local type = type or d
- if type == "f" then
- error("Don't use F. It downloads the file, which we don't want.")
- end
- local rand = http.get("http://www.random.org/cgi-bin/randbyte?nbytes="..length.."&format="..type.."", header)
- local result = rand.readAll()
- if result == "illegal format specified" then
- error("That's not a format! Formats are: d, h, o, b")
- end
- return result
- end
- function decimal(places,amount)
- quotaCheck()
- local places = places or 10
- local amount = amount or 1
- if places > 20 then
- error("Amount of places must be 1-20!")
- elseif places < 1 then
- error("Amount of places must be 1-20!")
- end
- local rand = http.get("http://www.random.org/decimal-fractions/?num="..amount.."&dec="..places.."&col=2&format=plain&rnd=new",header)
- local result = rand.readAll()
- return result
- end
- function getLostQuota()
- if not fs.exists(".quota") then
- local fuo = fs.open(".quota","w")
- fuo.writeLine(getQuota())
- fuo.close()
- end
- local fuo = fs.open(".quota","r")
- local current = tonumber(fuo.readAll())
- local result = current - getQuota()
- fuo.close()
- local fuo = fs.open(".quota","w")
- fuo.writeLine(tonumber(getQuota()))
- fuo.close()
- return result
- end
- function time(count)
- quotaCheck()
- local count = count or 1
- local rand = http.get("http://www.random.org/clock-times/?num="..count.."&earliest=01%3A00&latest=23%3A59&interval=5&format=plain&rnd=new", header)
- local result = rand.readAll()
- return result
- end
- function note(count)
- quotaCheck()
- local count = count or 1
- local rand = http.get("http://www.random.org/cgi-bin/jazz-scale?num="..count.."&key_c=on&key_g=on&key_d=on&key_a=on&key_e=on&key_b=on&key_fsharp=on&key_csharp=on&key_aflat=on&key_eflat=on&key_bflat=on&key_f=on&string_1=on&string_2=on&string_3=on&string_4=on&string_5=on&string_6=on&form_scale=on&type_major=on&type_minor_pent=on&type_major_pent=on&type_7th_pent=on", header)
- local result = rand.readAll()
- return result
- end
- function securestring(length,count) --Nobody can see the result but you
- quotaCheck()
- local count = count or 1
- local length = length or 8
- local rand = http.get("http://www.random.org/passwords/?num="..count.."&len="..length.."&format=plain&rnd=new", header)
- local result = rand.readAll()
- return result
- end
- function org()
- local result = "It's not like every function in this API connects to random.org or anything.."
- return result
- end
- function date(yearstart,yearend,count)
- quotaCheck()
- local yearstart = yearstart or 2014
- local yearend = yearend or 2014
- local rand = http.get("http://www.random.org/calendar-dates/?num="..count.."&start_day=1&start_month=1&start_year="..yearstart.."&end_day=31&end_month=12&end_year="..yearend.."&mondays=on&tuesdays=on&wednesdays=on&thursdays=on&fridays=on&saturdays=on&sundays=on&display=7&format=plain&rnd=new", header)
- local result = rand.readAll()
- return result
- end
- function gaussian(places,count,mean,stdev)
- quotaCheck()
- local mean = mean or 0.0
- local stdev = stdev or 1.0
- local count = count or 1
- local places = places or 10
- local rand = http.get("http://www.random.org/gaussian-distributions/?num="..count.."&mean="..mean.."&stdev="..stdev.."&dec="..places.."&col=2¬ation=scientific&format=plain&rnd=new")
- local result = rand.readAll()
- return result
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement