It was a long thread just a month ago regarding the same issue.
It discusses the disadvantages of using % for a random value,
and a proper way to do it.

For those who got stuck to MS documentation, and can't think of
anything apart from that, I would recommend a book:
"R.Sedgewick. Algorithms in C".

There are many other good books regarding common algorithms as well.

Michael


-----Original Message-----
From: Leon Heller [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 13 December 2001 7:57 AM
To: Palm Developer Forum
Subject: Re: Random number from 1 to 15





>From: Johnathan Smith <[EMAIL PROTECTED]>
>Reply-To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>Subject: Random number from 1 to 15
>Date: Wed, 12 Dec 2001 12:21:23 -0800 (PST)
>
>Can someone please show me how to make a random number
>from 1 to 15

How about this? I used the DJGPP DOS port of gcc. It should work with gcc 
for the Palm. It would be a good idea to seed the RNG (from the current 
time?) so you get a different sequence each time it is run.

/*
** random.c
**
** generate random number between 1 and 15
** uses gcc non-ANSI function random()
*/

#include <stdio.h>
#include <stdlib.h>

main()
{
        int x;

        for (;;)
        {
                x = (random() % 15) + 1;                        printf("%d
", x);

        }
}


Leon
--
Leon Heller, G1HSM Tel: +44 1327 359058 Email:[EMAIL PROTECTED]
My web page: http://www.geocities.com/leon_heller
My low-cost Altera Flex design kit: http://www.leonheller.com


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to