Profile


Name
LuaRandom
ID
101668
Shared with
Public
Parent
None
Children
None
Created on
December 09, 2015 at 06:48 AM UTC
Updated on
December 09, 2015 at 06:48 AM UTC
Description

Not a foldit recipe. This standalone Lua script generates a 512x512 random bitmap in PNG format.

Best for


Code


--[[ LuaRandom This script generates a random 512x512 black and white bitmap. Each bit is randomly selected. The goal is to visually assess the quality of the random number generator. In particular, a second script, LuaRandom2, can be used to generate a bit from the output of the random number generator found in foldit, via the randomeer recipe. 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 *outfile*.png where *outfile* is the output file name. revision history ---------------- 2015/12/08 -- LociOiling -- new function ]]-- -- -- I'd like to have an argument, please -- if arg == nil then print ( "LuaRandom is a standalone Lua program " ) print ( "(not a foldit recipe)" ) return end if #arg < 1 then print ( "usage: LuaRandom outfile" ) print ( "outfile is the output png file" ) return end require "gd" require "math" math.randomseed ( 1534345590 ) -- repeatable results math.random () -- for kk = 1, 10 do local zz zz = math.random ( 1, 10 ) print ( "random value " .. kk .. " = " .. zz ) end im = gd.createTrueColor ( 512, 512 ) white = im:colorAllocate ( 255, 255, 255 ) black = im:colorAllocate ( 0, 0, 0 ) for ii = 1, 512 do for jj = 1, 512 do if math.random ( 0, 1 ) == 1 then im:setPixel ( ii, jj, white ) end end end im:png ( arg [ 1 ] )

Comments


LociOiling Lv 1

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

This script generates a random 512x512 black and white bitmap.

Each bit is randomly selected.

The goal is to visually assess the quality of the random number generator. A second script, LuaRandom2, can be used to generate a bit from the output of the random number generator found in foldit, via the randomeer recipe. The two output files can then be compared.

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 *outfile*.png

where outfile is the output file name.