Code: Select all
input.buttonB.onEvent(ButtonEvent.Click, function () {
for (let i = 0; i < 20; i++) {
console.log(Math.randomRange(0, 10))
}
})
0,6,0,6,0,0,1,9,4,2,10,3,10,3,8,10,10,5,3,2
I don't have the hardware to test, but it looks like this is true for all SAMD21 boards (like CPX) in MakeCode. See the initRandomSeed() implementation here; the seed is fixed:
https://github.com/microsoft/pxt-common ... m.cpp#L121
As a workaround I made a function that uses the light + sound sensors to add entropy:
Code: Select all
let rand = 0
function getRandom(min: number, max: number): number {
rand = Math.randomRange(0, 255)
rand = rand + input.soundLevel()
rand = rand + input.lightLevel()
rand = rand / 3
rand = Math.round((rand % (max - min)) + min)
return rand
}
There's an open issue in GitHub: https://github.com/microsoft/pxt-adafruit/issues/1179