What should I do if I want to call random values from an array? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

What should I do if I want to call random values from an array?

Let's say I want my array to have these elements:{1,2,3,6} and I want to use the srand function for the elements from the array.Can it be done?

16th Jun 2018, 11:52 AM
Coj Seb
Coj Seb - avatar
6 Réponses
+ 6
I think you are talking about C++
16th Jun 2018, 12:08 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 1
make an array make a variable with a max random length of the array length print array[x] i used javascript var arr = ["array1","array2"]; var x = Math.random()*arr.length; console.log(arr[x]);
16th Jun 2018, 12:03 PM
Roel
Roel - avatar
+ 1
Yes,I was speaking about C++
16th Jun 2018, 12:29 PM
Coj Seb
Coj Seb - avatar
+ 1
So what options do we have in this case?
16th Jun 2018, 12:30 PM
Coj Seb
Coj Seb - avatar
16th Jun 2018, 12:47 PM
Calviղ
Calviղ - avatar
+ 1
Thanks a lot!
16th Jun 2018, 2:30 PM
Coj Seb
Coj Seb - avatar