home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!milano!cactus.org!cheselka
- From: cheselka@cactus.org (Michael R. M. Cheselka)
- Subject: srand() rand() question
- Message-ID: <1992Jul31.113913.22633@cactus.org>
- Organization: Capital Area Central Texas UNIX Society, PO Box 9786, Austin, TX 78766-9786
- Distribution: usa
- Date: Fri, 31 Jul 1992 11:39:13 GMT
- Lines: 46
-
- /* What is wrong with this program? Is it the multiple calls to srand()?
- rand() is not random at all, and soon duplicates it's self in a repeating
- pattern. Is it illegal to repeatedly call srand()? */
-
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
-
- /* The purpose of this program is to create a one megabyte( 1,048,576
- bytes) file containing only print and white space characters. Usefull to
- time modem speeds. The characters must be as random as posible, or
- else compression will skew the results. */
-
-
- main()
- {
- unsigned long count = 1048576;
- unsigned char character;
- unsigned int seed = 67483 ;
- srand( seed);
- while ( count > 0 )
- {
- character = rand();
- if (isprint(character))
- {
- printf("%c", character);
- --count;
- /* seed += 3; Trying for some extra randomness here...
- srand( seed); */
- }
- else if (isspace(character))
- {
- printf("%c", character);
- --count;
- /* seed += 5; And here, doesn't work...
- srand( seed); */
- }
- }
- }
- --
- cheselka@cactus.org N5UVV Michael R. M. Cheselka
- os9@gnu.ai.mit.edu (512)452-9412v ( 24hours answer. mach.)
- membership@cactus.org Hangs out on 145.21mhz 400 W. 34th st. #103
- {...}!cs.utexas!cactus.org!cheselka Austin, Texas, 78705-1331
-