Hi,

I would like to create a random packet of data, 128 bits long (16bytes).

My basic idea is to generate 16 pseudo-random numbers (between 0 and 255), then turn each of these numbers into their equivalent bytes. Then I intend to put these 16 bytes end to end to create my packet.

This is what I have so far:

Qt Code:
  1. void Loader::calculateRandomCode()
  2. {
  3. int n;
  4. n = qrand() % 255; // limits the random number to between 0 and 255
  5. QString qs = QString::number(n); // converts from int to string
  6. QLabel *label = new QLabel(qs); // prints to screen just so I can see whats going on
  7. label->show(); // prints to screen just so I can see whats going on
  8. }
To copy to clipboard, switch view to plain text mode 


How do I turn n into a byte?


Thanks for reading