1*9e66e6d7Sabs /* $NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */
20fbafa59Sjtc
30fbafa59Sjtc /*-
40fbafa59Sjtc * Copyright (c) 1990 The Regents of the University of California.
50fbafa59Sjtc * All rights reserved.
60fbafa59Sjtc *
70fbafa59Sjtc * Redistribution and use in source and binary forms, with or without
80fbafa59Sjtc * modification, are permitted provided that the following conditions
90fbafa59Sjtc * are met:
100fbafa59Sjtc * 1. Redistributions of source code must retain the above copyright
110fbafa59Sjtc * notice, this list of conditions and the following disclaimer.
120fbafa59Sjtc * 2. Redistributions in binary form must reproduce the above copyright
130fbafa59Sjtc * notice, this list of conditions and the following disclaimer in the
140fbafa59Sjtc * documentation and/or other materials provided with the distribution.
15eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
160fbafa59Sjtc * may be used to endorse or promote products derived from this software
170fbafa59Sjtc * without specific prior written permission.
180fbafa59Sjtc *
190fbafa59Sjtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
200fbafa59Sjtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
210fbafa59Sjtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220fbafa59Sjtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
230fbafa59Sjtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
240fbafa59Sjtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
250fbafa59Sjtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
260fbafa59Sjtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
270fbafa59Sjtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
280fbafa59Sjtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
290fbafa59Sjtc * SUCH DAMAGE.
300fbafa59Sjtc */
310fbafa59Sjtc
32bd906777Schristos #include <sys/cdefs.h>
330fbafa59Sjtc #if defined(LIBC_SCCS) && !defined(lint)
340fbafa59Sjtc #if 0
350fbafa59Sjtc static char *sccsid = "from: @(#)rand.c 5.6 (Berkeley) 6/24/91";
360fbafa59Sjtc #else
37*9e66e6d7Sabs __RCSID("$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $");
380fbafa59Sjtc #endif
390fbafa59Sjtc #endif /* LIBC_SCCS and not lint */
400fbafa59Sjtc
41b48252f3Slukem #include <assert.h>
42b48252f3Slukem #include <errno.h>
430fbafa59Sjtc #include <stdlib.h>
440fbafa59Sjtc
450fbafa59Sjtc int
rand_r(unsigned int * seed)46*9e66e6d7Sabs rand_r(unsigned int *seed)
470fbafa59Sjtc {
48b48252f3Slukem _DIAGASSERT(seed != NULL);
49b48252f3Slukem
500fbafa59Sjtc return ((*seed = *seed * 1103515245 + 12345) & RAND_MAX);
510fbafa59Sjtc }
52