aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorJoakim Verona2012-09-03 17:30:17 +0200
committerJoakim Verona2012-09-03 17:30:17 +0200
commit4a37733c693d59a9b83a3fb2d0c7f9461d149f60 (patch)
treea33402e09342f748baebf0e4f5a1e40538e620f4 /src/sysdep.c
parent5436d1df5e2ba0b4d4f72b03a1cd09b20403654b (diff)
parentdcde497f27945c3ca4ce8c21f655ef6f627acdd2 (diff)
downloademacs-4a37733c693d59a9b83a3fb2d0c7f9461d149f60.tar.gz
emacs-4a37733c693d59a9b83a3fb2d0c7f9461d149f60.zip
upstream
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 183ee005227..b84e6a4ea3a 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1765,19 +1765,37 @@ init_signals (void)
1765#endif /* !RAND_BITS */ 1765#endif /* !RAND_BITS */
1766 1766
1767void 1767void
1768seed_random (long int arg) 1768seed_random (void *seed, ptrdiff_t seed_size)
1769{ 1769{
1770#if defined HAVE_RANDOM || ! defined HAVE_LRAND48
1771 unsigned int arg = 0;
1772#else
1773 long int arg = 0;
1774#endif
1775 unsigned char *argp = (unsigned char *) &arg;
1776 unsigned char *seedp = seed;
1777 ptrdiff_t i;
1778 for (i = 0; i < seed_size; i++)
1779 argp[i % sizeof arg] ^= seedp[i];
1770#ifdef HAVE_RANDOM 1780#ifdef HAVE_RANDOM
1771 srandom ((unsigned int)arg); 1781 srandom (arg);
1772#else 1782#else
1773# ifdef HAVE_LRAND48 1783# ifdef HAVE_LRAND48
1774 srand48 (arg); 1784 srand48 (arg);
1775# else 1785# else
1776 srand ((unsigned int)arg); 1786 srand (arg);
1777# endif 1787# endif
1778#endif 1788#endif
1779} 1789}
1780 1790
1791void
1792init_random (void)
1793{
1794 EMACS_TIME t = current_emacs_time ();
1795 uintmax_t v = getpid () ^ EMACS_SECS (t) ^ EMACS_NSECS (t);
1796 seed_random (&v, sizeof v);
1797}
1798
1781/* 1799/*
1782 * Return a nonnegative random integer out of whatever we've got. 1800 * Return a nonnegative random integer out of whatever we've got.
1783 * It contains enough bits to make a random (signed) Emacs fixnum. 1801 * It contains enough bits to make a random (signed) Emacs fixnum.