micropython / micropython-esp32

Old port of MicroPython to the ESP32 -- new port is at https://github.com/micropython/micropython
MIT License
680 stars 219 forks source link

Is it really RANDOM ? #252

Closed curlyz closed 6 years ago

curlyz commented 6 years ago

Hi I am using (sysname='esp32', nodename='esp32', release='1.9.4', version='v1.9.4-644-g7de921 1b8 on 2018-10-13', machine='ESP32 module with ESP32')

Just doing some neopixel ring , 12 RGB .

from machine import *
from neopixel import *
from time import *
from random import randrange

n = NeoPixel(Pin(5) , 12 , timing = True)

for x in range(12):
  n[x] = (randrange(50),randrange(50),randrange(50))
  n.write()
  sleep_ms(10)

So . The weird thing is that whenever I press reset or plug in the USB , it show the same color , shouldn't it be random ?

Avi-TelnT commented 6 years ago

If you drive the neopixel with VCC=5V and ESP32 IO with 3V3 expect errors.

You can call my Skype nissim.test

From: curlyz [mailto:notifications@github.com] Sent: Monday, October 22, 2018 8:19 PM To: micropython/micropython-esp32 Cc: Subscribed Subject: [micropython/micropython-esp32] Is it really RANDOM ? (#252)

Hi I am using (sysname='esp32', nodename='esp32', release='1.9.4', version='v1.9.4-644-g7de921 1b8 on 2018-10-13', machine='ESP32 module with ESP32')

Just doing some neopixel ring , 12 RGB .

from machine import from neopixel import from time import * from random import randrange

n = NeoPixel(Pin(5) , 12 , timing = True)

for x in range(12): n[x] = (randrange(50),randrange(50),randrange(50)) n.write() sleep_ms(10)

So . The weird thing is that whenever I press reset or plug in the USB , it show the same color , shouldn't it be random ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/micropython/micropython-esp32/issues/252 , or mute the thread https://github.com/notifications/unsubscribe-auth/AfR3X39Xy9GbNRO29wWwVUX5WS8yMx9jks5unf3zgaJpZM4XzyW- . https://github.com/notifications/beacon/AfR3X1HRA1B-BH91Cc751qSf9SBQXCCOks5unf3zgaJpZM4XzyW-.gif

dpgeorge commented 6 years ago

shouldn't it be random ?

The random module is pseudo random and requires a seed value. Upon hard-reset the seed will be the same each time, so the sequence will be the same. To get different values you can seed it with the clock (assuming that changes), or use os.urandom() for true random numbers.