10 digit random number generator work with uin8_t

Hi there, I am new to programming and i'm looking to generate a random 10 digit number between "1000000000 and 2147483647" which i can do with the "random()" function but i would like to send it via an NRF module which uses "uint8_t and char".

Of someone could help me i would really appreciate it.

Post the code, following forum guidelines in the "How to use this forum" post.

I have taken out the random() function for the moment as i was trying different methods here is my code which is working:
Tx :

void loop()
{
uint8_t data[] = ("TEXT");
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
Serial.println((char*)data);
}

Rx :

void loop()
{
uint8_t data[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len3 = sizeof(data);
if (nrf24.waitAvailableTimeout(200))
{
    if (nrf24.recv(data, &len3))
    {
        Serial.println((char*)data);
        Serial.println("");
     }
}
}

The above codes work and "TEXT" is sent without issues.
I would like to generate a random 6-10 digit number which would replace "TEXT".
I have tried using different data types like "long" along with "random()" but the data gets corrupted.

How do you expect to get help with code that you can't bother to post?

Posting someone else's working code is a complete waste of your and our time.

This is the code im using ?????

No, that is not all the code you are using. That won't even compile. Please read the "How to use this forum" post, and follow the directions.

I have taken out the random() function

Maybe try this link...

https://forum.arduino.cc/index.php?topic=126541.0

http://forum.arduino.cc/index.php?topic=44620.0

Might need unsigned long for the format.

First you have to learn how to generate random numbers.
Do you know how?

You need those numbers to be within 1,000,000,000 and 2,147,483,647
Do know what data type to use?

Once you have that part of the code working, then you need to learn how to convert numbers into strings.

Ashley2708:
I have taken out the random() function

I really thought your question was about that exact part after reading OP.

Anyway, do take a look at itoa.

Hi there, yes i can generate the number range with the use of the random function without issues but it uses long as the data type.

I think i need to convert the output of the random function into a string which will then be sent as the uint8_t and display using char.

The reason for not posting all my code is there is a lot and this is the section of which i have the issue.

Well, there are two ways for that.

  1. convert the number in an ascii string using itoa().
  2. split it in four bytes using basic bit manipulation:
unsigned long l;
byte b[0] = l && 0xFF;
byte b[1] = (l >> 8) && 0xFF;
byte b[2] = (l >> 16) && 0xFF;
byte b[3] = (l >> 24) && 0xFF;

Ashley2708:
I think i need to convert the output of the random function into a string which will then be sent as the uint8_t and display using char.

The forum members are saying that you can send the 10 digit number by extracting each individual digit and sending each individual digit as an ascii character. The receiver collects up all those individual characters, and then a conversation will need to be made to get it back to a 'number' format......... that's if the receiving side needs the number in digital format.

Alternatively.... take the binary form of the number you want to send.... which might be 'N' bits in bit-length.... then that bunch of bits can be broken apart into groups of 8 bits.... so each group of 8 bits can be sent as a 'byte'. The receiving side will then have the task of reassembling the value once it receives all the relevant bytes. Sending the number in this bit pattern form is expected to be faster than the other method of sending 10 individual ascii characters (or 10 bytes).