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,329件の閲覧回数
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,184件の閲覧回数
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,184件の閲覧回数
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 件の賞賛
返信