moonbitlang / core

MoonBit's Core library
https://moonbitlang.com/
Apache License 2.0
475 stars 54 forks source link

A single Random state #514

Closed bobzhang closed 3 weeks ago

bobzhang commented 1 month ago

currently the random package has two type

struct RandomInt {
  state : FixedArray[Int]
  mut index : Int
}

struct RandomInt64 {
  state : FixedArray[Int64]
  mut index : Int
}

It would be nice to use only one type RandomState, so that we have

let default : RandomState  =  ...
pub fn init_state(...) {
}

In this case, it is convenient to use the API without passing around the seed why keep it flexible to seed the random package

bobzhang commented 1 month ago

cc @Lampese

Lampese commented 1 month ago

LGTM, and in fact, mt19937 is too slow, and most requirements don't need to be so strict. We have discussed before that the random provided by the compiler or using simpler random algorithms are necessary.

Unfortunately, I have been busy preparing for the NEMT recently and currently do not have time to complete this part of the writing.