#!/usr/bin/perl # Generate a (pseudo-)random set of binary variables. # Copyleft, T. J. Finney, 2002-11-17. Free for non-commercial use. # Set number of trials. $n = 10; # Set probability of a successful outcome. $p = 0.5; if (($p < 0) or (1 < $p)) { die "Probability must be between 0 and 1"; } srand(); for ($i = 0; $i < $n; $i++) { $var = rand(); if ($var < $p) { print "1"; } else { print "2"; } print "\t"; } print "\n";