# DevEUI for non-hardware assigned values

**URL:** <https://www.thethingsnetwork.org/forum/t/deveui-for-non-hardware-assigned-values/2093>\
**Category:** End Devices (Nodes)\
**Created:** [May 11, 2016, 12:28pm UTC](https://www.thethingsnetwork.org/forum/t/deveui-for-non-hardware-assigned-values/2093 "2016-05-11T12:28:31Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![terrillmoore](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/terrillmoore/32/47115_2.png) [@terrillmoore](https://www.thethingsnetwork.org/forum/u/terrillmoore)\
**Post date:** [May 13, 2016, 11:11pm UTC](https://www.thethingsnetwork.org/forum/t/deveui-for-non-hardware-assigned-values/2093/23 "2016-05-13T23:11:59Z")

</div>

You’ll have to judge whether you want to use a random ID. However, the definition of EUI-64 allows for this. The definition is given in chapter 8 of the IEEE-802 spec (freely available at [http://standards.ieee.org/getieee802/download/802-2014.pdf](http://standards.ieee.org/getieee802/download/802-2014.pdf)).

In section 8.2, they describe the u/l bit (bit 1) of byte 0 of EUI-64. If you set that bit, you have a “locally administered address”. Bit 0 always has to be zero for addresses. So a legitimate way of generating a random address, with very low probability of collision, is to generate 8 random bytes, then set bit 1 of byte 0, clear bit 0 of byte 0. On Ubuntu, this simple program will do what you need.

```auto
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/fcntl.h>
int main(int ac, char **av) {
    int fd, i;
    unsigned char eui[8];
    fd = open("/dev/random", O_RDONLY);
    if (fd < 0) {
        perror("can't open /dev/random");
        exit(1);
    }
    if (read(fd, eui, sizeof(eui)) != sizeof(eui)) {
        fprintf(stderr, "couldn't read %zu bytes\n", sizeof(eui));
        exit(1);
    }
    eui[0] = (eui[0] & ~1) | 2;
    for (i = 0; i < sizeof(eui); ++i) {
        printf("%02X%c", eui[i], i == sizeof(eui)-1 ? '\n' : '-');
    }
    return 0;
}

```

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/deveui-for-non-hardware-assigned-values/2093)._
