File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,13 +20,13 @@ package test
2020
2121import (
2222 "math/rand"
23- "time "
23+ "sync/atomic "
2424)
2525
2626var GreetingScript = []byte (`
2727transaction(greeting: String) {
28- execute {
29- log(greeting.concat(", World!"))
28+ execute {
29+ log(greeting.concat(", World!"))
3030 }
3131}
3232` )
@@ -135,21 +135,19 @@ func init() {
135135 greetingMsgUK ,
136136 greetingMsgES ,
137137 }
138-
139- rand .Seed (time .Now ().Unix ())
140138}
141139
142140type Greetings struct {
143- count int
141+ count atomic. Uint32
144142}
145143
146144func GreetingGenerator () * Greetings {
147- return & Greetings {0 }
145+ return & Greetings {}
148146}
149147
150148func (g * Greetings ) New () string {
151- defer func () { g .count ++ }( )
152- return greetings [g . count % len (greetings )]
149+ count := g .count . Add ( 1 )
150+ return greetings [count % uint32 ( len (greetings ) )]
153151}
154152
155153func (g * Greetings ) Random () string {
You can’t perform that action at this time.
0 commit comments