Ferric
7th January 2010, 02:18
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:
void Loader::calculateRandomCode()
{
int n;
n = qrand() % 255; // limits the random number to between 0 and 255
QString qs = QString::number(n); // converts from int to string
QLabel *label = new QLabel(qs); // prints to screen just so I can see whats going on
label->show(); // prints to screen just so I can see whats going on
}
How do I turn n into a byte?
Thanks for reading
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:
void Loader::calculateRandomCode()
{
int n;
n = qrand() % 255; // limits the random number to between 0 and 255
QString qs = QString::number(n); // converts from int to string
QLabel *label = new QLabel(qs); // prints to screen just so I can see whats going on
label->show(); // prints to screen just so I can see whats going on
}
How do I turn n into a byte?
Thanks for reading