-
Notifications
You must be signed in to change notification settings - Fork 271
/
random_blob.go
38 lines (32 loc) · 1.06 KB
/
random_blob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package namespace
import (
tmrand "github.com/tendermint/tendermint/libs/rand"
)
func RandomBlobNamespaceID() []byte {
return RandomBlobNamespaceIDWithPRG(tmrand.NewRand())
}
// RandomBlobNamespaceIDWithPRG returns a random blob namespace ID using the supplied Pseudo-Random number Generator (PRG).
func RandomBlobNamespaceIDWithPRG(prg *tmrand.Rand) []byte {
return prg.Bytes(NamespaceVersionZeroIDSize)
}
func RandomBlobNamespace() Namespace {
return RandomBlobNamespaceWithPRG(tmrand.NewRand())
}
// RandomBlobNamespaceWithPRG generates and returns a random blob namespace using the supplied Pseudo-Random number Generator (PRG).
func RandomBlobNamespaceWithPRG(prg *tmrand.Rand) Namespace {
for {
id := RandomBlobNamespaceIDWithPRG(prg)
namespace := MustNewV0(id)
err := namespace.ValidateBlobNamespace()
if err != nil {
continue
}
return namespace
}
}
func RandomBlobNamespaces(rand *tmrand.Rand, count int) (namespaces []Namespace) {
for i := 0; i < count; i++ {
namespaces = append(namespaces, RandomBlobNamespaceWithPRG(rand))
}
return namespaces
}