Go Package rand: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 18: Line 18:
i := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
i := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
</syntaxhighlight>
</syntaxhighlight>
Result: 8003690372325233432


=<tt>rand.NewSource()</tt>=
=<tt>rand.NewSource()</tt>=

Revision as of 21:45, 2 October 2023

Internal

Overview

The package math/rand.

rand.New()

Generating a new random integer:

import (
  "math/rand"
  "time"
)

i := rand.New(rand.NewSource(time.Now().UnixNano())).Int()

Result: 8003690372325233432

rand.NewSource()