September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
13
Task/Statistics-Basic/Zkl/statistics-basic-3.zkl
Normal file
13
Task/Statistics-Basic/Zkl/statistics-basic-3.zkl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var pipe=Thread.Pipe(); // used to connect the two threads
|
||||
fcn{ while(1){ pipe.write((0.0).random(1.0)) } }.launch(); // generator
|
||||
fcn{ // consumer/calculator
|
||||
N:=0; M:=SD:=sum:=ssum:=0.0;
|
||||
while(1){
|
||||
x:=pipe.read(); N+=1; sum+=x; ssum+=x*x;
|
||||
M=sum/N; SD=(ssum/N - M*M).sqrt();
|
||||
if(0==N%100000)
|
||||
println("N:%,10d mean:%.5f std dev:%.5f".fmt(N,M,SD));
|
||||
}
|
||||
}.launch();
|
||||
|
||||
Atomic.sleep(60*60); // wait because exiting the VM kills the threads
|
||||
Loading…
Add table
Add a link
Reference in a new issue