Python Forum
Generate String Only Unique to That Platform
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate String Only Unique to That Platform
#1
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.
Reply
#2
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
Reply
#3
(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 !
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sample random, unique string pairs from a list without repetitions walterwhite 1 401 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  generating random string unique forever Skaperen 5 2,286 Aug-20-2021, 07:15 AM
Last Post: Gribouillis
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,756 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  platform binary representation --- 3 questions Skaperen 4 2,710 Dec-05-2020, 03:50 AM
Last Post: Skaperen
  Generate unique random numbers from different lists Takeshio 5 3,697 May-24-2019, 07:29 PM
Last Post: ichabod801
  turtle moving platform chappie 1 2,969 Dec-06-2017, 10:52 PM
Last Post: chappie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020