Why is my random number generator with a range not corresponding with my output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is my random number generator with a range not corresponding with my output?

it works when u put it alone in the output box but with some other info and a array. it's not working. I think it has to do something with the array or for loop. boxes[x] = ran.nextInt((21-10)-1 + 1) + 10; } } https://code.sololearn.com/c2JyX7EXoPtZ/?ref=app

4th Apr 2018, 4:19 PM
Jaren Dogan
Jaren Dogan - avatar
1 Answer
+ 4
In your loop.... CHANGE: n1 = boxes[x]; TO: boxes[x] = n1; The problem is that you're assigning the value from your array to n1, rather than assigning the value of n1 to your array. As such, since your arrays are empty, they default to 0 and that's why you receive 0 as the output for the weight. Swapping those variables around will resolve the issue.
4th Apr 2018, 4:25 PM
Fata1 Err0r
Fata1 Err0r - avatar