arduino / arduino/ArduinoCore-avr

random(x*7)-function only gives smaller multiples of 7 on first call

Open
#371 10 comments 1 reaction 0 assignees View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

```
int n;

void setup() {
Serial.begin(9600);
randomSeed(analogRead(A0));
n = random(21);
Serial.println(n);
}
void loop() {
}
```
only outputs numbers from the set: {0,7,21}. All multiples of seven give back the smaller multiples of seven on the first call. I tested on arduino-hardware and on tinkercad (simulation).

incerely yours
shanty

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the sketch in setup() with randomSeed(analogRead(A0)) and random(21), then inspect the random() and randomSeed() entry points in ArduinoCore-avr. Compare the first-call output with subsequent calls and verify that the reported restriction no longer occurs across the Arduino hardware and Tinkercad cases described.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.