I am trying to create a RNG using CodeWarrior (hcs12 board) would that be possible?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I am trying to create a RNG using CodeWarrior (hcs12 board) would that be possible?

624 Views
dpk
Contributor I

trying to create slot machine. after generation of random number my idea is to compare the result and display it on LCD screen!

Labels (1)
0 Kudos
2 Replies

479 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

CW stdlib includes rand() function that generates a pseudo-random integer value.

then you can use sprintf() to print a number to string then post string to LCD

see this code

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

void main(void) {

  volatile int n;
  int i;
  char to_lcd[50];

  unsigned int seed;

  for (seed = 1; seed <5; seed++) {
  srand(seed);
  n=rand();
  sprintf(to_lcd, "%d", n);
  }
}


Hope this helps!


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

479 Views
dpk
Contributor I

Thank You Zhang!

It seems to be a good idea I will give it a try!

On Mon, Dec 12, 2016 at 2:46 AM, ZhangJennie <admin@community.nxp.com>

0 Kudos