Commit 9803fc41 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Use random() instead of rand() to increase portability

Quoting glibc rand(3):

The  versions  of rand() and srand() in the Linux C Library use the same random
number generator as random(3) and srandom(3), so the lower-order bits should be
as  random  as  the  higher-order bits.   However,  on  older  rand()
implementations, and on current implementations on different systems, the
lower-order bits are much less random than the higher-order bits.  Do not use
this function in applications intended to be portable when good randomness is
needed.  (Use random(3) instead.)
parent a9d46da6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -145,8 +145,8 @@ void init_collage_mode(void)
			}

			/* pick random coords for thumbnail */
			xxx = ((w - www) * ((double) rand() / RAND_MAX));
			yyy = ((h - hhh) * ((double) rand() / RAND_MAX));
			xxx = ((w - www) * ((double) random() / RAND_MAX));
			yyy = ((h - hhh) * ((double) random() / RAND_MAX));
			D(("image going on at x=%d, y=%d\n", xxx, yyy));

			im_thumb = gib_imlib_create_cropped_scaled_image(im_temp,
+1 −1
Original line number Diff line number Diff line
@@ -362,7 +362,7 @@ gib_list_randomize(gib_list * list)
   }
   for (i = 0; i < len - 1; i++)
   {
      r = i + rand() / (RAND_MAX / (len - i) + 1 );
      r = i + random() / (RAND_MAX / (len - i) + 1 );
      t = farray[r];
      farray[r] = farray[i];
      farray[i] = t;
+1 −1
Original line number Diff line number Diff line
@@ -686,7 +686,7 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy
	}
	else if (feh_is_kp(EVENT_jump_random, state, keysym, button)) {
		if (winwid->type == WIN_TYPE_THUMBNAIL)
			feh_thumbnail_select_next(winwid, rand() % (filelist_len - 1));
			feh_thumbnail_select_next(winwid, random() % (filelist_len - 1));
		else
			slideshow_change_image(winwid, SLIDE_RAND, 1);
	}
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ int main(int argc, char **argv)
{
	atexit(feh_clean_exit);

	srand(getpid() * time(NULL) % ((unsigned int) -1));
	srandom(getpid() * time(NULL) % ((unsigned int) -1));

	setup_signal_handlers();
	init_parse_options(argc, argv);
+1 −1
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ void slideshow_change_image(winwidget winwid, int change, int render)
		case SLIDE_RAND:
			if (filelist_len > 1) {
				current_file = feh_list_jump(filelist, current_file, FORWARD,
					(rand() % (filelist_len - 1)) + 1);
					(random() % (filelist_len - 1)) + 1);
				change = SLIDE_NEXT;
			}
			break;
Loading