Reputation: 9
I have an awk script which I called random.awk
that generate random number that approximates a normal distribution
#!/usr/bin/awk -f
#the sum of three uniform [-1,1] random variables is used to get the approximate normal distribution
#the first argument the number of random numbers to be generated, the default is 100
#the second argument is to get the mean value, the default is 0
#the third argument is to get the standard deviation, the default is 1
function prand(){
return(((rand()*2)-1)+((rand()*2)-1)+((rand()*2)-1));
}
BEGIN{
# establish default values
countnumber=(length(ARGV[1])==0?100:ARGV[1]);
meanvalue=(length(ARGV[2])==0?0.0:ARGV[2]);
stdeviation=(length(ARGV[3])==0?1.0:ARGV[3]);
for(i=0;i<count;i++){
printf("%.16e\n",prand()*stdeviation+meanvalue)
}
}
How do i create an awk file to uses the output of random.awk
as input and implements naive sum and mean computation?
Upvotes: 1
Views: 313
Reputation: 203219
Create an awk script like you just did for generating random values but implementing mean and sum calculations and pipe the output of your first script to your second one using the shell pipe symbol |
. If you'd like more help than that, you'd need to provide more information in your question.
Upvotes: 1