Skip to content

Random numbers generated needed fix#18

Open
zjasper122 wants to merge 1 commit intonicomp42:masterfrom
zjasper122:master
Open

Random numbers generated needed fix#18
zjasper122 wants to merge 1 commit intonicomp42:masterfrom
zjasper122:master

Conversation

@zjasper122
Copy link
Copy Markdown

Random.nextInt(int n) generates a random number in the range 0(inclusive) to n(exclusive).
We want to generate index for arrays flavors and UPCs randomly. So we need indexes from
0 to flavors.length-1 (both inclusive). So for upper bound we will have to add 1 to the upper bound
and the pass this to nextInt() method. So, correct call should be nextInt(flavors.length), then only it
will generate number from 0 to flavors.length-1 (both inclusive).

Random.nextInt(int n) generates a random number in the range 0(inclusive) to n(exclusive).
We want to generate index for arrays flavors and UPCs randomly. So we need indexes from
0 to flavors.length-1 (both inclusive). So for upper bound we will have to add 1 to the upper bound
and the pass this to nextInt() method. So, correct call should be nextInt(flavors.length), then only it
will generate number from 0 to flavors.length-1 (both inclusive).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant