#!/usr/local/bin/perl -w # # # for a relative difference set # # generates a vector of bits # of desired weight K, # and also checks for the difference set property - no difference (cyclic) # occurs more than once. # # randset.p N=500 K=5 # see also randgb.p for random grid of bits and randsubset.p # # used this Tue 7/5/02 to make quantum codes. # # intended final size of code: N=4000, M=1500. # j will be 3/4 of the K that we choose here. # So K=6 might work? # randset.p N=2000 K=6 $ds = 1 ; # whether to insist on the relative # difference set property $N = 40 ; # cols $K= 3 ; # weight $seed=0 ; $v=0;#verbosity eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if( ($ds==1) && ($K*($K-1) >= $N)) { print STDERR "You cannot be serious! suggest reducing K\n"; print STDERR " or switching ds=0 to allow difference property to lapse\n"; print STDERR "If you really want to do this set ds=2\nHALTING\n" ; exit(0); } srand ( $seed ) ; $dsnothappy = 1 ; do { print STDERR "." ; $M=$K ; $NN = $N ; $tot=0; for ( $n = 0 ; $n < $N ; $n ++ ) { if ( ($M *1.0/$NN) > rand() ) { $x[$n] = 1 ; $ind[$tot] = $n ; $tot ++ ; $M -- ; } else { $x[$n] = 0 ; } $NN -- ; } if (!($tot eq $K) ) { print STDERR "something is wrong $tot $K\n" ; } if($v) { print STDERR "tot=$tot\n" ; print "Made this x:\n" ; print join ( " ", @x ) ; print "\n" ; print "ind in reverse order:\n" ; for ( ; $tot >= 0 ; $tot -- ) { print $ind[$tot]."\n" ; } } ################### vector now made if($ds) { # check for difference property $clashes = 0 ; undef(@taken) ; $difflist="" ; for ( $i = 0 ; $i < $K ; $i ++ ) { $ni = $ind[$i] ; for ( $j = $i+1 ; $j < $K ; $j ++ ) { $nj = $ind[$j] ; print STDERR "finding diff $i $j\n" if($v) ; $diff = $nj - $ni ; if ( $taken{$diff} ) { $clashes ++ ; } else { $taken{$diff}="$ni.$nj"; } $difflist .= "$diff " ; } } if ( $clashes eq 0 ) { $dsnothappy = 0 ; } } else { $dsnothappy = 0 ; } } while ($dsnothappy) ; print join ( " ", @x ) ; print "\n" ; print STDERR " Differences were:\n$difflist\n" ;