MCPcopy
hub / github.com/segmentio/ksuid / NewRandomWithTime

Function NewRandomWithTime

ksuid.go:217–236  ·  view source on GitHub ↗
(t time.Time)

Source from the content-addressed store, hash-verified

215}
216
217func NewRandomWithTime(t time.Time) (ksuid KSUID, err error) {
218 // Go's default random number generators are not safe for concurrent use by
219 // multiple goroutines, the use of the rander and randBuffer are explicitly
220 // synchronized here.
221 randMutex.Lock()
222
223 _, err = io.ReadAtLeast(rander, randBuffer[:], len(randBuffer))
224 copy(ksuid[timestampLengthInBytes:], randBuffer[:])
225
226 randMutex.Unlock()
227
228 if err != nil {
229 ksuid = Nil // don't leak random bytes on error
230 return
231 }
232
233 ts := timeToCorrectedUTCTimestamp(t)
234 binary.BigEndian.PutUint32(ksuid[:timestampLengthInBytes], ts)
235 return
236}
237
238// Constructs a KSUID from constituent parts
239func FromParts(t time.Time, payload []byte) (KSUID, error) {

Callers 4

TestGetTimestampFunction · 0.85
testCompressedSetSparseFunction · 0.85
testCompressedSetMixedFunction · 0.85
NewRandomFunction · 0.85

Calls 1

Tested by 3

TestGetTimestampFunction · 0.68
testCompressedSetSparseFunction · 0.68
testCompressedSetMixedFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…