nearprotocol / near-runtime-ts

Typescript library for writing near smart contracts
22 stars 7 forks source link

fix random seed #75

Closed ailisp closed 5 years ago

ailisp commented 5 years ago

I'm still quite unsure about what to fix.

  1. This random32 is really a "random seed from current context". Do we want to rename to "random_seed_from_blockchain" and ask user to use it before using AssemblyScript's Math.random
  2. Do we want to implement a random without seed needed version api?
  3. Do we want randomBuffer?
vgrichina commented 5 years ago

@ailisp

  1. This random32 is really a "random seed from current context". Do we want to rename to "random_seed_from_blockchain" and ask user to use it before using AssemblyScript's Math.random

yeah, I'd rename it into random_seed and implement random32 to use this as a seed on first run, but then just continue generating sequence using some reasonably good PRNG

Math.random shouldn't be used as it operates on floats (mimicking JS)

Do we want to implement a random without seed needed version api?

Not sure what do you mean by "random without seed needed version api"

Do we want randomBuffer?

Yes

bowenwang1996 commented 5 years ago

I think random32() should actually return a generated number based on seed. At least that was the intention.

vgrichina commented 5 years ago

@bowenwang1996

I think random32() should actually return a generated number based on seed. At least that was the intention.

it's not clear whether you mean that it should return the same number every call or generate new number on each call

bowenwang1996 commented 5 years ago

It should generate a new number on each call. Will be useful when there are multiple calls to random32 in the same block

ailisp commented 5 years ago

@vgrichina

Do we want to implement a random without seed needed version api?

Not sure what do you mean by "random without seed needed version api"

I think your description of random32 is exactly I want here. sorry a duplicate question

@janedegtiareva

I think you already know the requirement before and I just understand after their answers. So would you still like to work on this or me?

ailisp commented 5 years ago

Close see #82