#!/usr/local/bin/perl -w # # generates a random grid of bits # randgb.p N=500 K=1 f=0.1 # see also randset.p # for a relative difference set $N = 12 ; # cols $K= 20 ; # rows $f=0.5 ; $seed=0 ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; srand ( $seed ) ; $tot=0; for ( $i = 1 ; $i <= $K ; $i ++ ) { for ( $n = 1 ; $n <= $N ; $n ++ ) { $x = ( rand() <= $f ) ? 1:0 ; print "$x " ; $tot += $x ; } print "\n" ; } print STDERR "tot=$tot\n" ;