Profile


Name
LuaRandom2
ID
101669
Shared with
Public
Parent
None
Children
None
Created on
December 09, 2015 at 06:47 AM UTC
Updated on
December 09, 2015 at 06:47 AM UTC
Description

Not a folidit recipe. This standalone Lua script reads the scriptlog output from the foldit recipe "Randomeer" and produces a PNG bitmap.

Best for


Code


--[[ LuaRandom2 This script generates a random 512x512 black and white bitmap from a the output of the foldit "Randomeer" recipe. The goal is to visually assess the quality of the random number generator. The output from this script can be compared to a similar bit map generated by the LuaRandom script. See https://www.random.org/analysis/#visual for a detailed example This script is based on the PHP script found in http://boallen.com/random-numbers.html This script is shared as a foldit recipe, but requires a standalone Lua environment. This is a command line LUA program. The command line syntax is: lua LuaRandom.lua *scriptlog* *outfile*.png where *scriptlog* is the foldit script log from the randomeer recipe, (for example, scriptlog.default.xml) and *outfile* is the output file name. revision history ---------------- 2015/12/08 -- LociOiling -- new function ]]-- DEBUG = false -- -- I'd like to have an argument, please -- if arg == nil then print ( "LuaRandom2 is a standalone Lua program " ) print ( "(not a foldit recipe)" ) return end if #arg < 2 then print ( "usage: LuaRandom2 infile outfile" ) print ( "infile is the scriptlog file from the Randomeer recipe" ) print ( "outfile is the output png file" ) return end require "gd" math.randomseed ( os.time () % 1000000 ) math.random () im = gd.createTrueColor ( 512, 512 ) white = im:colorAllocate ( 255, 255, 255 ) ii = 0 for line in io.lines ( arg [ 1 ] ) do -- -- ignore simple XML tags in foldit scriptlog format -- start, stop, tag = line:find ( "(<*>)" ) -- not 100% but close enough if tag == nil then ii = ii + 1 if ii == 1 and DEBUG then print ( "length of line = " .. #line ) print ( "string length of line = " .. string.len ( line ) ) print ( "type of line = " .. type ( line ) ) print ( "type of line [ 1 ] = " .. type ( line [ 1 ] ) ) foo = {} for jj = 1, 10 do print ( "random " .. jj .. " = " .. string.sub ( line, jj, jj ) ) foo [ jj ] = string.sub ( line, jj, jj ) end print ( "size of foo = " .. #foo ) print ( "type of foo = " .. type ( foo ) ) for jj = 1, 10 do print ( "foo [ " .. jj .. " ] = " .. foo [ jj ] ) end end for jj = 1, 512 do if string.sub ( line, jj, jj ) == '1' then im:setPixel ( ii, jj, white ) end end end end print ( ii .. " lines read" ) print ( "\n" ) im:png ( arg [ 2 ] )

Comments


LociOiling Lv 1

This is a standalone command-line Lua script, not a foldit recipe.

This script processes the scriptlog output of the foldit "Randomeer" recipe to produce a bitmap in PNG format.

The goal is to visually assess the quality of the random number generator. The output from this script can be compared to the output of the LuaRandom script.

See https://www.random.org/analysis/#visual for a detailed example

This script is based on the PHP script found in http://boallen.com/random-numbers.html

This script is shared as a foldit recipe, but requires a standalone Lua environment.

This is a command-line LUA program. The command line syntax is:

lua LuaRandom.lua scriptlog outfile.png

where scriptlog is the foldit script log from the randomeer recipe, (for example, scriptlog.default.xml) and outfile is the output file name.