Last active
February 6, 2019 20:47
-
-
Save morningtoast/f1d02464f8300742c363dc4b7b055436 to your computer and use it in GitHub Desktop.
Pico8 seeding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pico-8 cartridge // http://www.pico-8.com | |
| version 16 | |
| __lua__ | |
| -- seeding testing | |
| -- goal is to use the date as seed value, which will make it so | |
| -- the sequence of values coming out of the pool are the same | |
| -- every time the cart is reset | |
| function rand_table(t) | |
| local r=flr(rnd(#t))+1 | |
| local pick=t[r] | |
| return pick | |
| end | |
| function in_table(n,h) | |
| local exists=false | |
| for _,v in pairs(h) do | |
| if v==n then exists=true end | |
| end | |
| return exists | |
| end | |
| pats={1,2,3,4,5,6,7,8,9} -- pool of possibles | |
| seed=sub(stat(80),-2)..stat(81)..stat(82)/10 -- make seed out of date parts YYMMDD, no zeroes. need to /10 the day to avoid going over int limit | |
| --seed=4 | |
| function _init() | |
| cls() | |
| srand(seed) | |
| -- go through pool and pull out value when its not already in the output table | |
| outs={} | |
| for _,v in pairs(pats) do | |
| local p=rand_table(pats) | |
| while in_table(p,outs) do | |
| p=rand_table(pats) | |
| end | |
| add(outs,p) | |
| end | |
| -- display | |
| x,y=0,30 | |
| print("seed="..seed,0,10,11) | |
| for _,v in pairs(outs) do | |
| print(v, x,y, 12) | |
| x+=10 | |
| end | |
| end | |
| function _update() end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment