Re: Choosing a Random Number in Array
in
Programming Questions
•
1 year ago
I am trying to solve this exercise but i don't get the solution.
Randomly the computer has to choose one of the Arrays as the “best” number. In the window I need to have a message that shows what the array is and which the sketch considers the best. These should always change.
I hope so much someone can help me, I have an exam soon...
This is my code but I am doing something wrong.
Thanks!
- float [] HelloArray= new float [int(random(5,11))];
- float HelloArrayBest= float (random(HelloArray.length));
- void setup(){
- size(400,400);
- fill(0);
- for (int i=0; i<HelloArray.length; i++){
- HelloArray[i] = random(100);
- }
- }
- void draw(){
- background(255);
- for (int i=0; i<HelloArray.length; i++){
- float HelloArrayBest= float (random(HelloArray.length));
- text("Item"+" "+i+" "+"is"+" "+ HelloArray[i]+(HelloArray[HelloArrayBest]),50,150+i*20);
- }
- println(HelloArray);
- }
1