]> git.sesse.net Git - jam/commitdiff
Add a Pareto random number generator.
authorsgunderson@bigfoot.com <>
Wed, 31 Jan 2007 20:13:08 +0000 (21:13 +0100)
committersgunderson@bigfoot.com <>
Wed, 31 Jan 2007 20:13:08 +0000 (21:13 +0100)
jam.c

diff --git a/jam.c b/jam.c
index 3b38d0217587f00d08e319eee7a1f5191f190599..e81e166d4bebe403217155a7b2d4b2f0fac417e7 100644 (file)
--- a/jam.c
+++ b/jam.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <math.h>
 #include <string.h>
 #include <stdlib.h>
 #include <getopt.h>
@@ -28,6 +29,12 @@ const static struct option longopts[] = {
        { NULL, 0, NULL, 0 }
 };
 
+double gen_pareto_random(double min, double k)
+{
+       double u = rand() / (RAND_MAX+1.0);
+       return min * pow(u, -1.0 / k);
+}
+
 void read_ip_list(char *filename, struct in_addr **addr_list, unsigned *num, unsigned *room)
 {
        char buf[256];
@@ -113,7 +120,15 @@ void parse_options(int argc, char **argv)
 
 void *sender_worker(void *arg)
 {
+       unsigned i;
+
        printf("Dummy sender worker\n");
+
+       for (i = 0; i < 1000; ++i) {
+               unsigned bytes = (unsigned)gen_pareto_random(1048576.0, 1.0);
+               printf("Sending %u bytes\n", bytes);
+       }
+
        pthread_exit(0);
 }