1a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes/*	$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $	*/
2a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes
3a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes/*-
4a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * Copyright (c) 1990 The Regents of the University of California.
5a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * All rights reserved.
6a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *
7a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * Redistribution and use in source and binary forms, with or without
8a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * modification, are permitted provided that the following conditions
9a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * are met:
10a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * 1. Redistributions of source code must retain the above copyright
11a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *    notice, this list of conditions and the following disclaimer.
12a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright
13a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *    notice, this list of conditions and the following disclaimer in the
14a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *    documentation and/or other materials provided with the distribution.
15a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * 3. Neither the name of the University nor the names of its contributors
16a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *    may be used to endorse or promote products derived from this software
17a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *    without specific prior written permission.
18a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes *
19a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes * SUCH DAMAGE.
30a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes */
31a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes
32a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#include <sys/cdefs.h>
33a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#if defined(LIBC_SCCS) && !defined(lint)
34a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#if 0
35a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesstatic char *sccsid = "from: @(#)rand.c	5.6 (Berkeley) 6/24/91";
36a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#else
37a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes__RCSID("$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
38a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#endif
39a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#endif /* LIBC_SCCS and not lint */
40a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes
41a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#include <assert.h>
42a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#include <errno.h>
43a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes#include <stdlib.h>
44a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes
45a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesint
46a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughesrand_r(unsigned int *seed)
47a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes{
48a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes	_DIAGASSERT(seed != NULL);
49a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes
50a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes	return ((*seed = *seed * 1103515245 + 12345) & RAND_MAX);
51a0beeeabbc8735bc830544cbbb1d920122b8d958Elliott Hughes}
52