AnsweredAssumed Answered

Non repetitive Random Number generator

Question asked by Utsavi Kalpesh Bharuchwala on Jun 23, 2015
Latest reply on Jun 25, 2015 by Radek Sestak

Hi,

 

I am working with code warrior v10.6 and of MQX v4.0.

 

I am generating random numbers using srand(); followed by rand(); and it is generating random numbers perfectly.

 

But what problem I am facing is when module restart it again start to generate random number from scratch.(I am attaching snapshot)

 

Instead I want to escape those numbers which are already generated before module restart. Is there any Idea to do this??

 

I am doing this thing manually by storing last seed of srand function before my module reset but I dont want to do this...

 

Is there any ready made function available to do this??

 

Here is my code generating Random Numbers:

 

void Main_task(uint_32 initial_data)

{

       srand(0);

       while(1)

       {

            _time_delay(1000);

            printf("rand number: %d \n",rand());

       }

 

}

Outcomes