Tuesday, September 6, 2016

Kana Hanazawa (花澤 香菜): 恋愛サーキュレーション

Kana Hanazawa

Crontab: Tweet Random Line without Modulo Bias

Command:

$ crontab -l


Result:

*/30 * * * * perl -le 'sleep rand 360' && csv="list.csv"; wc=$[`wc -l < $csv` - 1]; rand=$[`./rand_nobias.sh $wc`]; head -$[$[$rand \% $wc] + 2] $csv | tail -1 | /usr/local/bin/gawk -f formatcsv.awk | ruby tweet.rb 

Bourne shell: Generating Random Number without Modulo Bias

Command: 

$ cat rand_nobias.sh


Result:

#!/bin/sh

numlines=$1;
randmax=32767;
max=$((($randmax/$numlines)*$numlines)); 
rand=$RANDOM;

until [ $rand -lt $max ] 
do 
rand=$RANDOM;
done 


echo $rand;