---
title: "How to Random.choice Equivalent in Java for an Array?"  
description: "How to Random.choice Equivalent in Java for an Array?"  
author: "Pravesh Singh"  
published: 2014-11-04  
updated: 2014-11-04  
canonical: https://www.mindstick.com/forum/2513/how-to-random-choice-equivalent-in-java-for-an-array  
category: "java"  
tags: ["python-3.4", "netbeans"]  
reading_time: 1 minute  

---

# How to Random.choice Equivalent in Java for an Array?

Here is an example of my [random](https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c).[choice](https://yourviews.mindstick.com/view/80821/it-s-not-easy-to-make-a-right-choice) [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) in Python.

```
available_cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'TeamLeader', 'Rohit', 'Kesharwani', 'Alld']
random_computer_card = random.choice(available_cards)
print random_computer_card
```

Just wondering what the [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) equivalent would be for this piece of code. Obviously, I haven't included the [import](https://www.mindstick.com/blog/294/how-to-import-or-export-sql-server-table-data-in-ms-excel-sheet-using-c-sharp-code) statement in the sample.

## Replies

### Reply by Barbara Jones

Convert everything to String and define them in an array like below and access from index by generating random number:

```
String[] available_cards = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "TeamLeader", "Rohit", "Kesharwani", "Alld"}; java.util.Random
random = new
java.util.Random();int random_computer_card =
random.nextInt(available_cards.length);System.out.println(available_cards[random_computer_card]);
```


---

Original Source: https://www.mindstick.com/forum/2513/how-to-random-choice-equivalent-in-java-for-an-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
