delorie.com/archives/browse.cgi | search |
From: | Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com> |
Message-Id: | <199705301905.AA173899113@typhoon.rose.hp.com> |
Subject: | Re: Random numbers |
To: | Bennett AT btinternet DOT com (Matthew Bennett) |
Date: | Fri, 30 May 1997 12:05:12 PDT |
Cc: | djgpp AT delorie DOT com |
In-Reply-To: | <01bc6ce9$72076bc0$363e63c3@8652hvt73761>; from "Matthew Bennett" at May 30, 97 11:09 am |
> printf("%d\n", random() & 10); ^^^^^^^ You are specifying a bitwise AND here. This is equivalent to a modula for numbers that are 2^n -1, but not in your case. The simplest way to get what you want is to do randowm() % 10. Note that this can bias some numbers. Check the mail archives for details on getting more 'random' random numbers. Past 3 months should do it. Andrew
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |