1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: brandom.c,v 1.2 2003/02/22 02:07:27 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* brandom.c - blue noise function. |
6 |
* |
7 |
* 11/8/87 |
8 |
*/ |
9 |
|
10 |
#include "random.h" |
11 |
|
12 |
|
13 |
double |
14 |
brandom(l) /* blue noise function */ |
15 |
int l; /* length between 1 and 8 */ |
16 |
{ |
17 |
static float his[8] = {.5,.5,.5,.5,.5,.5,.5,.5}; |
18 |
static double avg = .5; |
19 |
static int x = 0; |
20 |
double y = frandom(); |
21 |
|
22 |
if (avg < .5) |
23 |
y = 1 - 2*y*avg; |
24 |
else |
25 |
y = 2*y*(1 - avg); |
26 |
/* update */ |
27 |
avg += (y - his[x])/l; |
28 |
his[x] = y; |
29 |
if (++x >= l) x = 0; |
30 |
|
31 |
return(y); |
32 |
} |