/[avr-libc]/avr-libc/libc/stdlib/random.c
ViewVC logotype

Contents of /avr-libc/libc/stdlib/random.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2.2.1 - (show annotations) (download)
Wed Apr 1 23:12:11 2009 UTC (16 years, 6 months ago) by arcanum
Branch: avr-libc-1_6-branch
CVS Tags: avr-libc-1_6_8-release, WinAVR-20100110, avr-libc-1_6_7-release
Changes since 1.2: +6 -1 lines
File MIME type: text/plain
2009-04-01  Eric B. Weddington  <eric.weddington@atmel.com>

	Put all functions in .text.avr-libc section, floating point math
	routines in .text.avr-libc.fplib section.
	* common/sectionname.h: New file.
	* common/asmdef.h: Fix spelling in comments. Change default linker
	section.
	* common/gasava.inc: Comment out macro that is no longer being used.
	* common/macros.inc: Add include file.
	* devtools/gen-avr-lib-tree.sh: Remove use of -mcall-prologues on 2
	xmega devices.
	* libc/misc/eerd_block.c: Change linker section.
	* libc/misc/eerd_dword.c: Same.
	* libc/misc/eerd_word.c: Same.
	* libc/misc/eewr_block.c: Same.
	* libc/misc/eewr_dword.c: Same.
	* libc/misc/eewr_word.c: Same.
	* libc/misc/itoa.S: Same.
	* libc/misc/ltoa.S: Same.
	* libc/misc/mul10.S: Same.
	* libc/misc/mulsi10.S: Same.
	* libc/misc/ultoa.S: Same.
	* libc/misc/utoa.S: Same.
	* libc/pmstring/memchr_P.S: Same.
	* libc/pmstring/memcmp_P.S: Same.
	* libc/pmstring/memcpy_P.S: Same.
	* libc/pmstring/strcasecmp_P.S: Same.
	* libc/pmstring/strcat_P.S: Same.
	* libc/pmstring/strchr_P.S: Same.
	* libc/pmstring/strcmp_P.S: Same.
	* libc/pmstring/strcpy_P.S: Same.
	* libc/pmstring/strcspn_P.S: Same.
	* libc/pmstring/strlcat_P.S: Same.
	* libc/pmstring/strlcpy_P.S: Same.
	* libc/pmstring/strlen_P.S: Same.
	* libc/pmstring/strncasecmp_P.S: Same.
	* libc/pmstring/strncat_P.S: Same.
	* libc/pmstring/strncmp_P.S: Same.
	* libc/pmstring/strncpy_P.S: Same.
	* libc/pmstring/strnlen_P.S: Same.
	* libc/pmstring/strpbrk_P.S: Same.
	* libc/pmstring/strrchr_P.S: Same.
	* libc/pmstring/strsep_P.S: Same.
	* libc/pmstring/strspn_P.S: Same.
	* libc/pmstring/strstr_P.S: Same.
	* libc/stdio/clearerr.c: Same.
	* libc/stdio/fclose.c: Same.
	* libc/stdio/fdevopen.c: Same.
	* libc/stdio/feof.c: Same.
	* libc/stdio/ferror.c: Same.
	* libc/stdio/fgetc.c: Same.
	* libc/stdio/fgets.c: Same.
	* libc/stdio/fprintf.c: Same.
	* libc/stdio/fprintf_p.c: Same.
	* libc/stdio/fputc.c: Same.
	* libc/stdio/fputs.c: Same.
	* libc/stdio/fputs_p.c: Same.
	* libc/stdio/fread.c: Same.
	* libc/stdio/fscanf.c: Same.
	* libc/stdio/fscanf_p.c: Same.
	* libc/stdio/fwrite.c: Same.
	* libc/stdio/getc.S: Same.
	* libc/stdio/getchar.c: Same.
	* libc/stdio/gets.c: Same.
	* libc/stdio/printf.c: Same.
	* libc/stdio/printf_p.c: Same.
	* libc/stdio/putc.S: Same.
	* libc/stdio/putchar.c: Same.
	* libc/stdio/puts.c: Same.
	* libc/stdio/puts_p.c: Same.
	* libc/stdio/scanf.c: Same.
	* libc/stdio/scanf_p.c: Same.
	* libc/stdio/snprintf.c: Same.
	* libc/stdio/snprintf_p.c: Same.
	* libc/stdio/sprintf.c: Same.
	* libc/stdio/sprintf_p.c: Same.
	* libc/stdio/sscanf.c: Same.
	* libc/stdio/sscanf_p.c: Same.
	* libc/stdio/ultoa_invert.S: Same.
	* libc/stdio/ungetc.c: Same.
	* libc/stdio/vfprintf.c: Same.
	* libc/stdio/vfprintf_p.c: Same.
	* libc/stdio/vfscanf.c: Same.
	* libc/stdio/vfscanf_p.c: Same.
	* libc/stdio/vprintf.c: Same.
	* libc/stdio/vscanf.c: Same.
	* libc/stdio/vsnprintf.c: Same.
	* libc/stdio/vsnprintf_p.c: Same.
	* libc/stdio/vsprintf.c: Same.
	* libc/stdio/vsprintf_p.c: Same.
	* libc/stdlib/abort.S: Same.
	* libc/stdlib/abort.c: Same.
	* libc/stdlib/abs.c: Same.
	* libc/stdlib/assert.c: Same. And use standard function declaration.
	* libc/stdlib/atof.S: Same.
	* libc/stdlib/atoi.S: Same.
	* libc/stdlib/atoi.c: Same.
	* libc/stdlib/atol.S: Same.
	* libc/stdlib/atol.c: Same.
	* libc/stdlib/bsearch.c: Same. And use standard function declaration.
	* libc/stdlib/calloc.c: Same.
	* libc/stdlib/ctype.S: Same.
	* libc/stdlib/div.S: Same.
	* libc/stdlib/dtoa_prf.c: Same.
	* libc/stdlib/dtostre.c: Same.
	* libc/stdlib/dtostrf.c: Same.
	* libc/stdlib/exit.S: Same.
	* libc/stdlib/ftoa_engine.S: Same.
	* libc/stdlib/labs.c: Same.
	* libc/stdlib/ldiv.S: Same.
	* libc/stdlib/malloc.c: Same.
	* libc/stdlib/qsort.c: Same. And use standard function declaration.
	* libc/stdlib/rand.c: Same.
	* libc/stdlib/random.c: Same.
	* libc/stdlib/realloc.c: Same.
	* libc/stdlib/setjmp.S: Same.
	* libc/stdlib/strtod.c: Same.
	* libc/stdlib/strtol.c: Same. And use standard function declaration.
	* libc/stdlib/strtoul.c: Same. And use standard function declaration.
	* libc/string/ffs.S: Same.
	* libc/string/ffsl.S: Same.
	* libc/string/ffsll.S: Same.
	* libc/string/memccpy.S: Same.
	* libc/string/memchr.S: Same.
	* libc/string/memcmp.S: Same.
	* libc/string/memcpy.S: Same.
	* libc/string/memmem_P.S: Same. And add missing copyright and license,
	with permission from Dmitry Xmelkov.
	* libc/string/memmove.S: Same.
	* libc/string/memset.S: Same.
	* libc/string/strcasecmp.S: Same.
	* libc/string/strcasestr_P.S: Same. And add missing copyright and
	license, with permission from Dmitry Xmelkov.
	* libc/string/strcat.S: Same.
	* libc/string/strchr.S: Same.
	* libc/string/strcmp.S: Same.
	* libc/string/strcpy.S: Same.
	* libc/string/strcspn.S: Same.
	* libc/string/strdup.c: Same.
	* libc/string/strlcat.S: Same.
	* libc/string/strlcat.c: Same. And remove dead code.
	* libc/string/strlcpy.S: Same.
	* libc/string/strlcpy.c: Same. And remove dead code.
	* libc/string/strlen.S: Same.
	* libc/string/strlwr.S: Same.
	* libc/string/strncasecmp.S: Same.
	* libc/string/strncat.S: Same.
	* libc/string/strncmp.S: Same.
	* libc/string/strncpy.S: Same.
	* libc/string/strnlen.S: Same.
	* libc/string/strpbrk.S: Same.
	* libc/string/strrchr.S: Same.
	* libc/string/strrev.S: Same.
	* libc/string/strsep.S: Same.
	* libc/string/strspn.S: Same.
	* libc/string/strstr.S: Same.
	* libc/string/strtok.c: Same.
	* libc/string/strtok_r.S: Same.
	* libc/string/strupr.S: Same.
	* libm/fplib/fp32def.h: Same.
	* NEWS: Add item.

1 /*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * Posix rand_r function added May 1999 by Wes Peters <wes@softweyr.com>.
30 *
31 * $Id: random.c,v 1.2 2007/01/08 15:06:53 joerg_wunsch Exp $
32 */
33
34 /*
35 * From:
36 static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93";
37 */
38
39 #include <stdlib.h>
40 #include "sectionname.h"
41
42 ATTRIBUTE_CLIB_SECTION
43 static long
44 do_random(unsigned long *ctx)
45 {
46 /*
47 * Compute x = (7^5 * x) mod (2^31 - 1)
48 * wihout overflowing 31 bits:
49 * (2^31 - 1) = 127773 * (7^5) + 2836
50 * From "Random number generators: good ones are hard to find",
51 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
52 * October 1988, p. 1195.
53 */
54 long hi, lo, x;
55
56 x = *ctx;
57 /* Can't be initialized with 0, so use another value. */
58 if (x == 0)
59 x = 123459876L;
60 hi = x / 127773L;
61 lo = x % 127773L;
62 x = 16807L * lo - 2836L * hi;
63 if (x < 0)
64 x += 0x7fffffffL;
65 return ((*ctx = x) % ((unsigned long)RANDOM_MAX + 1));
66 }
67
68
69 ATTRIBUTE_CLIB_SECTION
70 long
71 random_r(unsigned long *ctx)
72 {
73 return do_random(ctx);
74 }
75
76
77 static unsigned long next = 1;
78
79 ATTRIBUTE_CLIB_SECTION
80 long
81 random(void)
82 {
83 return do_random(&next);
84 }
85
86 ATTRIBUTE_CLIB_SECTION
87 void
88 srandom(unsigned long seed)
89 {
90 next = seed;
91 }
92

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26