~ubuntu-branches/ubuntu/raring/avr-libc/raring-proposed

« back to all changes in this revision

Viewing changes to libc/stdlib/rand.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2007-08-09 11:28:01 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070809112801-ps7wognnynio9kz7
Tags: 1:1.4.6-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 *
29
29
 * Posix rand_r function added May 1999 by Wes Peters <wes@softweyr.com>.
30
30
 *
31
 
 * $Id: rand.c,v 1.2 2002/10/16 15:52:25 joerg_wunsch Exp $
 
31
 * $Id: rand.c,v 1.2.8.1 2007/01/08 15:10:36 joerg_wunsch Exp $
32
32
 */
33
33
 
34
34
/*
60
60
         */
61
61
        long hi, lo, x;
62
62
 
63
 
        hi = *ctx / 127773L;
64
 
        lo = *ctx % 127773L;
 
63
        x = *ctx;
 
64
        /* Can't be initialized with 0, so use another value. */
 
65
        if (x == 0)
 
66
                x = 123459876L;
 
67
        hi = x / 127773L;
 
68
        lo = x % 127773L;
65
69
        x = 16807L * lo - 2836L * hi;
66
 
        if (x <= 0)
 
70
        if (x < 0)
67
71
                x += 0x7fffffffL;
68
72
        return ((*ctx = x) % ((unsigned long)RAND_MAX + 1));
69
73
#endif  /* !USE_WEAK_SEEDING */