Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random/Zufallszahl 0.0 - 1.0 won't work because of integer division #1643

Closed
Andy1978 opened this issue Mar 12, 2024 · 0 comments
Closed

Random/Zufallszahl 0.0 - 1.0 won't work because of integer division #1643

Andy1978 opened this issue Mar 12, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Andy1978
Copy link

Andy1978 commented Mar 12, 2024

Following sketch
grafik

translates to

...
float ___x;
task main() {
    ___x = 0;
    while ( true ) {
        ___x = Random(100) / 100;
        NumOut(0, (MAXLINES - 1) * MAXLINES, ___x);
        NumOut(0, (MAXLINES - 2) * MAXLINES, Random(100) / 100);
        Wait(1000);
    }
}

which always shows

0
0

due to integer division. The simulations shows the expected float values. A fix would be to use Random(100) / 100.0, I'll provide a patch for this soon

Andy1978 pushed a commit to Andy1978/openroberta-lab that referenced this issue Mar 12, 2024
Random(100) / 100 always evaluates to 0 due to integer division.
The provided patch forces a floating point division.

Tested on NXT with nbc 1.2.1.r4 and original Lego firmware 1.29
@bjost2s bjost2s added the bug Something isn't working label Mar 14, 2024
@rbudde rbudde assigned rbudde and unassigned bjost2s Apr 3, 2024
rbudde pushed a commit that referenced this issue Apr 3, 2024
Random(100) / 100 always evaluates to 0 due to integer division.
The provided patch forces a floating point division.

Tested on NXT with nbc 1.2.1.r4 and original Lego firmware 1.29
AyaMoussa pushed a commit that referenced this issue Apr 4, 2024
Random(100) / 100 always evaluates to 0 due to integer division.
The provided patch forces a floating point division.

Tested on NXT with nbc 1.2.1.r4 and original Lego firmware 1.29
@bjost2s bjost2s closed this as completed Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants