Hello everyone,

I have seen the Random interface generates random numbers of 16 or 32
bits long. How can I generate a 8 bit random numbers array?

void generateRandomArray(uint8_t * array, uint8_t size)
{
   uint8_t i;
   uint16_t aux;
   uint8_t *p = (uint8_t *)&aux;

    for (i=0; i < size / 2; i++)
   {
         aux = call Random.rand16();
         array[i] = *p;          //Store the MSB
         array[i+1] = *(p+1); //Store the LSB
   }
}

I am not very good at pointers that's why I don't know if this works
fine. By the way, I guess the array contents are modified within the
function but these are also valid outside, right?

Thanks in advance
-- 
Ruben
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to