ranf.c revision 1.7
1254721Semaste/*	$OpenBSD: ranf.c,v 1.7 2016/01/07 14:37:51 mestre Exp $	*/
2254721Semaste/*	$NetBSD: ranf.c,v 1.3 1995/04/22 10:59:21 cgd Exp $	*/
3254721Semaste
4254721Semaste/*
5254721Semaste * Copyright (c) 1980, 1993
6254721Semaste *	The Regents of the University of California.  All rights reserved.
7254721Semaste *
8254721Semaste * Redistribution and use in source and binary forms, with or without
9254721Semaste * modification, are permitted provided that the following conditions
10254721Semaste * are met:
11254721Semaste * 1. Redistributions of source code must retain the above copyright
12254721Semaste *    notice, this list of conditions and the following disclaimer.
13254721Semaste * 2. Redistributions in binary form must reproduce the above copyright
14254721Semaste *    notice, this list of conditions and the following disclaimer in the
15254721Semaste *    documentation and/or other materials provided with the distribution.
16254721Semaste * 3. Neither the name of the University nor the names of its contributors
17254721Semaste *    may be used to endorse or promote products derived from this software
18254721Semaste *    without specific prior written permission.
19254721Semaste *
20254721Semaste * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23254721Semaste * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29254721Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30254721Semaste * SUCH DAMAGE.
31254721Semaste */
32254721Semaste
33254721Semaste#include <stdlib.h>
34254721Semaste
35254721Semasteint
36254721Semasteranf(int max)
37254721Semaste{
38254721Semaste	int	t;
39254721Semaste
40254721Semaste	if (max <= 0)
41254721Semaste		return (0);
42254721Semaste	t = random() >> 5;
43254721Semaste	return (t % max);
44254721Semaste}
45254721Semaste
46254721Semaste
47254721Semastedouble
48254721Semastefranf(void)
49254721Semaste{
50254721Semaste	double		t;
51254721Semaste	t = random() & 077777;
52254721Semaste	return (t / 32767.0);
53254721Semaste}
54254721Semaste