mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
examples/life: Fix initial world randomization (#1045)
Because golang executes the init function after establishing the variables in the var block, the random number seed wasn't initializing until after the initial world state had gotten established (leading to an identical game of Life on every run). To fix this, we establish an empty world in the var block, and then populate it in the init function after the random number generator has been seeded.
This commit is contained in:
parent
9be3495077
commit
7ee8d1aa5f
@ -53,6 +53,7 @@ func NewWorld(width, height int, maxInitLiveCells int) *World {
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
world = NewWorld(screenWidth, screenHeight, int((screenWidth*screenHeight)/10))
|
||||
}
|
||||
|
||||
// init inits world with a random state.
|
||||
@ -156,7 +157,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
world = NewWorld(screenWidth, screenHeight, int((screenWidth*screenHeight)/10))
|
||||
world *World
|
||||
pixels = make([]byte, screenWidth*screenHeight*4)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user