Go Down

Topic: Bug: Random() always returns lowest value (Read 965 times) previous topic - next topic

starwarslegokid

Hello Everyone,

Have found an interesting problem on my samD21 and would like peoples help tracking down how to fix it.

The random function appears to always return the lowest value possible. Afew lines and print statements have lead me to these observations:

random(32000); // always returns 0
random(0,5); // always returns 0
random(1,3); // always returns 1

Can anyone else confirm this is the case on their boards as well? I am using a Atmel SamD21 Xplained board and want to see if it is a bug with generic samD21 libraries, or related to this board and my included board files.

Scott

sandeepmistry

Hi Scott/@starwarslegokid,

It seems ok my Arduino Zero, here's my test sketch and the output:

Code: [Select]

void setup() {
  Serial.begin(9600);
  while (!Serial);
}

void loop() {
  Serial.println(random(32000));
  Serial.println(random(0,5));
  Serial.println(random(1,3));
  Serial.println();

  delay(5000);
}



Code: [Select]

5752
1
1

30119
1
2

12843
0
1

18393
0
1

28169
2
2

21847
2
1

22980
3
2

23592
4
2

30551
2
1

14624
0
1

11944
0
1

30484
3
2

26710
1
1

30431
4
2

4675
1
1

19344
4
2

9629
0
2

29126
3
1

30104
0
2

29620
1
1


starwarslegokid

Hello sandeepmistry!

Thank you for the reply, something must be going on with my board file libraries. I will go poking around there and see if I find anything.

Thanks!
Scott

steddyrobots

I'm having the same issue. Did you find the solution?

Go Up