Python Forum

Full Version: Generate String Only Unique to That Platform
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

Could someone enlighten me,
How can I get a piece of string , say 6 characters mix of alpha & numbers,
only unique to that platform ?

Or at least some concept how can I do that?

I need to auto-generate a hostname,
in which even after multiple reboots,
Or re-installation of software,
this piece of code shouldn't generate a new name.

Generating out of MAC address is 1 way,
but it gets complicated especially in Python 2.7 getting to know which network card is active and so on so forth.

Looking for something easy and straight-forward.
Can use uuid.
It provides the uniqueness as it generates ids on the basis of time,Computer hardware (MAC etc.).
>>> import uuid
>>> 
>>> str(uuid.uuid4())[:6]
'5a7fce'
Quote:especially in Python 2.7
Then stop using Python 2.7 Hand
(Sep-10-2019, 03:33 PM)snippsat Wrote: [ -> ]Can use uuid.
It provides the uniqueness as it generates ids on the basis of time,Computer hardware (MAC etc.).
>>> import uuid
>>> 
>>> str(uuid.uuid4())[:6]
'5a7fce'
Quote:especially in Python 2.7
Then stop using Python 2.7 Hand

Yes but UUID is different everytime u run it.
I need the same I'd to be generated everytime for the same platform.

About py2.7 I wish u could come n tell those people chg to py3 !