Random in stack | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Random in stack

How can I pick random number in stack?

2nd Mar 2018, 6:27 PM
Saya
1 Answer
0
If you are talking about the “stack” data structure then you can’t. The whole point of a stack is to access the value of ONE element at a time from the ‘top’ of the stack a.k.a the last element that was appended to it. So in order to pick a random number from a list of values use an array or ArrayList and use the standard random package supplied with Java.
2nd Mar 2018, 9:43 PM
TurtleShell
TurtleShell - avatar