go - https://github.com/seehuhn/fortuna 的问题,或者我误解了 Golang
问题描述
我正在尝试将https://github.com/seehuhn/fortuna用于 Golang 并将其实现到 API 中。
我遇到的问题是,当我分配 *fortuna.Accumulator 并将其分配给我的 App 结构时,我无法在创建它的函数体之外使用它。
请参见下面的示例。
type App struct {
Config config.Config
RNG *fortuna.Accumulator
Sink chan<- time.Time
}
func New(cfg config.Config) *App {
var acc, err = fortuna.NewRNG(cfg.SeedFileName)
if err != nil {
panic("cannot initialise the RNG: " + err.Error())
}
defer acc.Close()
app := App{Config: cfg, RNG: acc, Sink: sink}
/// if i use app.RNG.Uint64() <--- using this here works correctly
return &app
package main
import (
"******/*******/app"
)
func main() {
app := app.New(cfg)
app.RNG.Uint64() <--- this causes Generator not seeded yet error
}
解决方案
所以你推迟通话
acc.Close()
女巫有效地杀死了RNG。
推荐阅读
- csv - 通过 Zapier 将多选值从 typeform 传递到 Salesforce
- javascript - 为什么即使没有使用数组排序方法分配数组也会反转?
- python - Django 1.10 - 每 X 秒使用数据库中的数据更新网页
- performance - SSD 性能参数 - 延迟与 IOPS?
- javascript - textarea.append() 在手动输入后停止工作
- java - 列出具有预定义大小或没有大小的可变参数
- android - 从一个 android 应用程序向另一个应用程序连续发送数据
- python - 通配符错误 - “无效选项”
- batch-file - 基于模式匹配的批处理文件中的舒适程序执行作为一个衬垫
- docker - Docker - 在 $PATH 中找不到可执行文件