Skip to content

Instantly share code, notes, and snippets.

@Prince781
Created September 22, 2014 03:16
Show Gist options
  • Select an option

  • Save Prince781/df6633dbe671461bf0ae to your computer and use it in GitHub Desktop.

Select an option

Save Prince781/df6633dbe671461bf0ae to your computer and use it in GitHub Desktop.
Generates data from a prime list.
#!/bin/sh
# gendata.sh
function print_ij() {
# print j'th field (column) of the i'th line
awk -v i=$1 -v j=$2 'FNR == i {print $j}' $3
}
function gendata() {
n=$(($1 - 1))
fname=$2
for i in $(seq 0 $n); do
modulus=`print_ij $((1 + $i / 9)) $((1 + $i % 9)) $fname`
val=$(($RANDOM % $modulus))
if [ $val -eq 0 ]; then val=1; fi
echo $val $modulus
done | parallel echo {} > output.txt
}
gendata $1 $2
# ex: ./gendata 200 primes.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment