I am developing an application for peer-peer conversation in ad-hoc network. when a peer wants to communicate with other peer, it uses its ip address to connect. Once devices connected with each other in an Ad-hoc network, a IP address is assigned to each one of them, but I need a smaller string(of 4-6 character) as a unique ID for each device in an ad-hoc network. Since this is a peer-peer network, there is no server(which can generate unique ID), so it is a responsibility of each peer itself to generate unique ID. I am searching for a mechanism or algorithm to generate the unique ID in java.
Asked
Active
Viewed 275 times
2
-
which is the programming language – 134 Apr 03 '17 at 11:19
-
1Just need an Idea or mechanism to do it. – Nirmal_stack Apr 03 '17 at 11:25
-
1@134 Do you have solution for this problem? – Nirmal_stack Apr 03 '17 at 12:20
-
yes please try the answer which is given below(java) – 134 Apr 03 '17 at 12:26
2 Answers
1
This is probably best solved by use of each device's interface specific MAC address. MAC addresses are, in standard implementation, unique to each network interface, so each one of your devices already has a unique number. You can use this address directly or as a seed value to create derived IDs.

Liam Kelly
- 3,524
- 1
- 17
- 41
0
Use the below code for generating random numbers with 6 characters
private static SecureRandom random = new SecureRandom();
public static String getUniqueId() {
return new BigInteger(130, random).toString(32).substring(0, 6);
}

134
- 28
- 8