From: cziwkga AT ulcc DOT ac DOT uk (Kevin Ashley) Newsgroups: comp.os.msdos.djgpp Subject: Re: Help! Random is not working right Date: 8 Apr 1997 13:08:49 GMT Organization: University of London Computer Centre Lines: 16 Distribution: world Message-ID: <5idg11$iqr@calypso.ulcc.ac.uk> References: <3349B612 DOT 68C AT ucsu DOT Colorado DOT edu> Reply-To: k DOT ashley AT ulcc DOT ac DOT uk NNTP-Posting-Host: silver-e.ulcc.ac.uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <3349B612 DOT 68C AT ucsu DOT Colorado DOT edu>, William Heymann writes: > |>random() & 9 only returns 0, 1, 8, and 9. That's all it can return. "&" means bit-wise and. 9 only has the 8 bit and the 1 bit on, and the only numbers you can make with those bits are 0,1 8 and 9. If you want numbers in a range, you need to do a modulo divide: random() % 10 will give you numbers between 0 and 9, inclusive. ------------------------------------------------------------------------------ Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk Development Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley University of London Computer Centre. ...ukc!ncdlab!K.Ashley This is not a signature