aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-04 00:39:32 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-04 00:39:32 +0000
commit53d5a280d243a05aabb278351c55bd3e08943c1f (patch)
treeb08199e8166ff0a325378c6b6588674f3314bcf0
parent4bad1ea4a92d330db5ce5e563315de398a63ea21 (diff)
improve portability, replace arc4random() with srandom()/random(), remove setterm()
-rw-r--r--weasel.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/weasel.c b/weasel.c
index ef86a16..49d35dc 100644
--- a/weasel.c
+++ b/weasel.c
@@ -22,7 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <term.h>
+#include <time.h>
#include <unistd.h>
#define NUM_THREADS 10
@@ -57,7 +57,7 @@ struct creature {
char
rndchar()
{
- return alphabet[arc4random() % (sizeof(alphabet) - 1)];
+ return alphabet[random() % (sizeof(alphabet) - 1)];
}
float
@@ -116,7 +116,7 @@ printpopulation(int maximal)
struct creature *
pickrandom(int population)
{
- int n = arc4random() % population;
+ int n = random() % population;
cp = SLIST_FIRST(&generation);
while (n-- > 0 && cp)
@@ -153,10 +153,10 @@ intercourse(int population, int mutationsrate)
qsort(c, 3, sizeof(struct creature *), cmp);
for (i = 0; i < c[2]->length; i++) {
- if (arc4random() % mutationsrate == 0)
+ if (random() % mutationsrate == 0)
c[2]->genom[i] = rndchar();
else
- c[2]->genom[i] = c[arc4random() % 2]->genom[i];
+ c[2]->genom[i] = c[random() % 2]->genom[i];
}
c[2]->genom[i] = '\0';
c[2]->fitness = calculatefitness(c[2]->genom, c[2]->length);
@@ -222,7 +222,7 @@ main(int argc, char **argv)
aim = argc ? strdup(*argv) : defaim;
initscr();
- setterm("vt220");
+ srandom(time(NULL));
initpopulation(strlen(aim), population);
args.population = population;