1 #include <time.h> /* For time() */
2 #include <stdio.h> /* For NULL */
3 #include <stdlib.h> /* For rand() and srand() */
4
5 #include <grass/gis.h>
6 #include <grass/raster.h>
7 #include <grass/glocale.h>
8
9 #define MAX_COLORS 1024
10 #define DEVIATION 128
11
12
13 /*!
14 * \brief make random colors
15 *
16 * Generates random colors. Good as a first pass at a
17 * color table for nominal data.
18 *
19 * \param colors
20 * \param min
21 * \param max
22 * \return
23 */
24
Rast_make_random_colors(struct Colors * colors,CELL min,CELL max)25 void Rast_make_random_colors(struct Colors *colors, CELL min, CELL max)
26 {
27 unsigned char red, grn, blu;
28 int count;
29 CELL n;
30
31 Rast_init_colors(colors);
32 if (min > max)
33 G_fatal_error(_("Rast_make_random_colors: min (%d) > max (%d)"),
34 min, max);
35
36 /* FIXME - allow seed to be specified for repeatability */
37 G_srand48_auto();
38
39 count = MAX_COLORS - DEVIATION + G_lrand48() % DEVIATION;
40 if (count > max - min + 1)
41 count = max - min + 1;
42
43 for (n = 1; n <= count; n++) {
44 red = G_lrand48() & 0xff;
45 grn = G_lrand48() & 0xff;
46 blu = G_lrand48() & 0xff;
47 Rast_add_modular_c_color_rule(&n, red, grn, blu,
48 &n, red, grn, blu, colors);
49 }
50 Rast_set_c_color_range(min, max, colors);
51 }
52