# How to generate a random number on 9215.

**URL:** <https://forums.digi.com/t/how-to-generate-a-random-number-on-9215/12893>\
**Category:** Embedded Devices\
**Tags:** connectcore9p9215, cc9215, netos\
**Created:** [May 1, 2014, 3:41pm UTC](https://forums.digi.com/t/how-to-generate-a-random-number-on-9215/12893 "2014-05-01T15:41:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsantana](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hsantana](https://forums.digi.com/u/hsantana)\
**Post date:** [May 1, 2014, 3:41pm UTC](https://forums.digi.com/t/how-to-generate-a-random-number-on-9215/12893/1 "2014-05-01T15:41:47Z")

</div>

I am trying to generate a random number in the 0-255 range. I am using srand and rand. In order to generate the seed with srand I am using a value taken from the ticks passed since board was on.

If I run my program using JTag it will work correctly. This means that every time I run it, I will get a different number.

In the other hand, when I download the code to the board and run it without JTAG, I am getting the same result on every run. I check the ticks passed and I am using different numbers to create the seed on every run.

Any solution to generate a random number each time?

Thanks,

---

<div class="post-metadata">

**Author:** ![dakotas\_dad](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dakotas\_dad](https://forums.digi.com/u/dakotas_dad)\
**Post date:** [May 2, 2014, 7:58am UTC](https://forums.digi.com/t/how-to-generate-a-random-number-on-9215/12893/2 "2014-05-02T07:58:17Z")

</div>

Hello

There are a couple of things that come to mind, they could also be used in combination.

1. when calling srand pass it as a parameter the current system time.

2. There is an undocumented call entitled GetFullEth0Stats. it is located in \bsp\devices\common\ethernet  
aeth.c. YOU pass it a pointer to an ETH\_STATS structure (see \h\efe\_def.h). An ETH\_STATS structure contains all sorts of juicy ethernet statistics. You could call this and add a couple of the statistics together and use that as a param in calling srand.

3. Pass the system time added to a sum of a couple of the ethernet stats as described above to srand.

see if that/those help.
