MCPcopy Index your code
hub / github.com/moby/moby / GenerateRandomID

Function GenerateRandomID

daemon/internal/stringid/stringid.go:40–60  ·  view source on GitHub ↗

GenerateRandomID returns a unique, 64-character ID consisting of a-z, 0-9. It guarantees that the ID, when truncated ([TruncateID]) does not consist of numbers only, so that the truncated ID can be used as hostname for containers.

()

Source from the content-addressed store, hash-verified

38// of numbers only, so that the truncated ID can be used as hostname for
39// containers.
40func GenerateRandomID() string {
41 b := make([]byte, 32)
42 for {
43 if _, err := rand.Read(b); err != nil {
44 panic(err) // This shouldn't happen
45 }
46 id := hex.EncodeToString(b)
47
48 // make sure that the truncated ID does not consist of only numeric
49 // characters, as it's used as default hostname for containers.
50 //
51 // See:
52 // - https://github.com/moby/moby/issues/3869
53 // - https://bugzilla.redhat.com/show_bug.cgi?id=1059122
54 if allNum(id[:shortLen]) {
55 // all numbers; try again
56 continue
57 }
58 return id
59 }
60}
61
62// allNum checks whether id consists of only numbers (0-9).
63func allNum(id string) bool {

Callers 15

generateIDAndNameMethod · 0.92
NewExecConfigFunction · 0.92
BenchmarkDBAdd100Function · 0.92
copySrcMethod · 0.92
makePluginCreatorFunction · 0.92
newJournaldFunction · 0.92
NewRWLayerMethod · 0.92
CommitMethod · 0.92
ChangesMethod · 0.92

Calls 2

allNumFunction · 0.85
ReadMethod · 0.45

Tested by 12

BenchmarkDBAdd100Function · 0.74
createNetworkDBInstancesFunction · 0.74
TestNetworkDBIslandsFunction · 0.74
newTestPluginFunction · 0.74
TestGetOrphanFunction · 0.74
createLayerFunction · 0.74
TestGenerateRandomIDFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…