This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Rnadom numbers


After I figured out how to do random and eliminated the access violation
when trying to do time functions, here's a little more random version
for getting different numbers for different runs.


program listing
---------------
#include <stdio.h>
#include <stdlib.h>
#include <winbase.h>
main()
{
int myvalue;

static SYSTEMTIME SystemTime;

GetSystemTime(&SystemTime);

srand(SystemTime.wMilliseconds); /* use millisecond timer as seed for
srand *

myvalue = rand();

srand(myvalue); /* more randomness */

myvalue = ((float)rand()/RAND_MAX)*100.0; /* scale from 0 to 100 */

printf("%d\n",myvalue);
myvalue = ((float)rand()/RAND_MAX)*100.0; /* scale from 0 to 100 */

printf("%d\n",myvalue);
}

Seems to work fine for me.
Donated to public domain
#include <no_warranties>
#include <other_disclaimers>
-- 
Bartlee A. Anderson     System Test (Interfaces-Tools-Automation-ISDN)
Rockwell International                    Electronic Commerce Division
300 Bauman Ct.                                banders@ecd.rockwell.com
MS 933-605      Opinions my own, not Rockwell's   VOICE (630) 227-8975
Wood Dale, IL 60191                               FAX   (630) 227-9771
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]