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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

1,315 次查看
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!

标签 (1)
0 项奖励
回复
2 回复数

1,170 次查看
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 项奖励
回复

1,170 次查看
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 项奖励
回复