Quote:
Originally posted by Mistwolf
I don't want to send my integers as characters, I want to send them as ints (casting them to characters makes them take more space).
No it doesn't. If your int is, say, 4 bytes long, then casting will give you an array of 4 characters. But see
this post for a discussion of the macros you should use.
Quote:
Another quick question - is there any *easy* way to generate random integers in a certain range? i.e. 1-1000 instead of 1-2^16 ?
If "oldrand" is a random number in the range 1 to 2^16 then use something like:
mymax = 1000;
newrand = oldrand*mymax/(2^16);
But take a look at the docs for your random number generator. Is the range 2^16 or 2^15? You want to get this right.
Quote:
How about generating random lowercase characters a-z?
Same problem really:
mymax = (int)'z' - (int)'a' + 1;
newrand = oldrand*mymax/(2^16);
ranchar = (char) ((int)'a' + newrand);