Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Feb 1999 21:36:40 -0500 (EST)
From:      Patrick Seal <patseal@hyperhost.net>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Random Numbers
Message-ID:  <Pine.BSF.4.05.9902162134210.809-100000@foobar.hyperhost.net>

next in thread | raw e-mail | index | archive | help
In this the best way to get a number from one to ten in C:

#include <stdlib.h>

randn(float value) {
    value = random() * value / 2147483648.0;
    return(value);
}

n = randn(10.0) + 1

printf("%i", n);

I realize it's platform dependent.  Is there a better way?

------------------------------------ _____________________________________
Patrick Seal                        |"Microsoft isn't evil, they just make
<patseal@hyperhost.net>             |   really crappy operating systems."
Hyperhost - http://www.hyperhost.net| -Linus Torvalds
hosting and Design

http://www.freebsd.org - http://www.linux.org






To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9902162134210.809-100000>