From: ara howard Date: 2008-02-02T02:30:26+09:00 Subject: Re: [QUIZ] Parsing JSON (#155) On Feb 1, 2008, at 9:09 AM, Eric Mahurin wrote: > Maybe just have a little ruby > script that generates a stream of repeatable random (but valid) JSON. cfp2:~ > cat a.rb require 'rubygems' require 'json' def random_json case rand when 0 ... 1/3.0 top = Hash.new add = lambda{|obj| top[obj] = obj} when 1/3.0 ... 2/3.0 top = Array.new add = lambda{|obj| top.push obj} when 2/3.0 .. 1 top = String.new add = lambda{|obj| top += obj} end 10.times{ add[rand.to_s] } top.to_json end puts random_json cfp2:~ > for i in `seq 1 3`;do ruby a.rb ;done "0.3786779826911330.2475380034343990.7052927081471540.2056530009384740.1367079874315110.6433874613518640.5329060341883540.8932613322492760.9233991888762390.561470121133217 " {"0.758942077040095":"0.758942077040095","0.740998718448961":"0.740998718448961","0.581975309640819":"0.581975309640819","0.471066491788047":"0.471066491788047","0.150752108985123":"0.150752108985123","0.679712508205116":"0.679712508205116","0.265444532310993":"0.265444532310993","0.43229805237576":"0.43229805237576","0.880407977937905":"0.880407977937905","0.91896885679168":"0.91896885679168"} ["0.140526101058637 ","0.647296447390116 ","0.419874655921874 ","0.67320818546074 ","0.847043108967541 ","0.479385904117001 ","0.378678170026127 ","0.707315391952609","0.26064520446906","0.460184583302929"] a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama