Skip to content

gnovm: random global variable pary #4182

Open
@paulogarithm

Description

@paulogarithm

Description

related to #4039, this describes a deeper issue on the gnovm.

problematic : how do we manage random global variable to store the seed ?

to make random, we need a seed that will define the overall state of the randomness, with some pseudo random methods to edit the number based on the seed, with chaotic-like maths evaluations.

but here, in gno, we cant store anything in a stdlib, because it (kind of) act like a pure package, so how to counter that ?

so as thehowl said here, we must get rid of the global variable, but how do we store the seed ?

Golang singleton

so one way would be to create a function to get the seed as a global variable internal to gno, so the global object is coded in the gno software (so coded in golang) and the function to get the object is called in gno

func GetGlobalSeed() *Rand

so instead of using this globalRand variable, we could actually call GetGlobalSeed() and this function will return the Rand object from gno software directly, and not stored in a gno file.

Use a pseudo realm package

since pure packages cant store variables, why not using packages that behaves like the r/ packages (that can actually hold data) and require it in the rand

import "r/rand/global"

global.Random.hi = x

so i know we cant directly use gno.land/r packages in stdlibs, since we have to differenciate gno and gno.land, but its just an idea

Give up

just remove the random, since some people thinks its useless in gno, because it leads to less predicatable behaviours.

Do you have any other ideas ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions