Edit: Chris Stratton rightfully points out that the question is
double, not a
Most, but not all Arduinos, are AVR-based.
In the following I assume you are talking about AVR doubles, i.e.
floats. If this is not the case, then just replace the array of 4 bytes
by an array of 8 bytes.
float is four bytes, so it is somewhat equivalent to an array of
four unsigned chars, i.e. to
unsigned char. You can use this
equivalence with an
union. For example, the following function will
send a float byte by byte:
void ble_write_float(float x)
unsigned char c;
data.f = x;
Notice that this will send the bytes in whatever is the natural order of
the sending processor. If it's an AVR (like most Arduinos), this will be
LSB (least significant byte) first. You have to make sure that this is
what the receiver expects.
Following Ignacio Vazquez-Abrams' suggestion, for sending a random float
you could just send four random bytes. However, it may be wiser to have
an idea of the random distribution you want for your float, and use
map() to achieve that distribution. Using
four random bytes, you get a very wide distribution (all the possible
floats are equally likely) which includes weird things like denormals,
infinities and NaN (literally meaning “not a number”).