creating pseudorandom number in PIC C

shwaipshwaip bluffin' with my muffin Icrontian
edited July 2005 in Internet & Media
I'm working on a project for a PIC 16F87, and I need a "random" number between (inclusive) 0 and 15. I've been looking for something on the internet, and I can't find anything that I really understand.

The randomness of the sequence serves no integral purpose, it's only for aestetics (displaying 1 of 16 messages), but I would like it to appear to be random. The PIC C compiler should be able to handle a regular C algorithm, but I really have almost no experience with PICC. Usually I write in assembly on the PIC.

Thanks.

Comments

  • mmonninmmonnin Centreville, VA
    edited July 2005
    http://www.cplusplus.com/ref/cstdlib/rand.html
    printf ("A number between 0 and 99: %d\n", rand()%100);
    printf ("A number between 20 and 29: %d\n", rand()%10+20);

    So in your case rand()%16 since you want 0 to 15.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited July 2005
    thanks - I thought I looked through all the libs that came with the PIC C compiler, but apparently I missed this one.
  • mmonninmmonnin Centreville, VA
    edited July 2005
    We had a lab where we had to do some random numbers in one of my C++ courses.
Sign In or Register to comment.