# Select random element from list

**URL:** <https://discourse.processing.org/t/select-random-element-from-list/28178>\
**Category:** Coding Questions\
**Created:** [March 2, 2021, 9:12am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178 "2021-03-02T09:12:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Criste44](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Criste44](https://discourse.processing.org/u/Criste44)\
**Post date:** [March 2, 2021, 9:12am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/1 "2021-03-02T09:12:51Z")

</div>

I want to select a random element from a list and make an if operation on the selected item. Can I do them in void awake or void start?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [March 2, 2021, 9:42am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/2 "2021-03-02T09:42:32Z")

</div>

Its unclear what you want.

---

<div class="post-metadata">

**Author:** ![Criste44](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Criste44](https://discourse.processing.org/u/Criste44)\
**Post date:** [March 2, 2021, 9:58am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/3 "2021-03-02T09:58:43Z")

</div>

int sayi;

Random rastgele = new Random();  
int sayi = rastgele.Next(1,4);

if (sayi = 1)  
{ İnitialSetup1}

İf else (sayı = 2)  
{ İnitialSetup2}

Where can I do this?

---

<div class="post-metadata">

**Author:** ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)\
**Post date:** [March 2, 2021, 10:13am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/4 "2021-03-02T10:13:36Z")

</div>

I’m not sure to understand well.

```auto
int rand = int(random(2));
if(rand==0){
    print("first setup");
}else if(rand==1){
    print("second setup");
}

```

---

<div class="post-metadata">

**Author:** ![Criste44](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Criste44](https://discourse.processing.org/u/Criste44)\
**Post date:** [March 2, 2021, 10:27am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/5 "2021-03-02T10:27:16Z")

</div>

Boolean&) ameManager.cs(57,20): error CS1525: Invalid expression term 'int

he gave an error

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [March 2, 2021, 10:27am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/6 "2021-03-02T10:27:24Z")

</div>

Well theres only one use of setup in processing. So youd have to put your condition inside the setup functions and make setup1 and setup2 functions outside your setup or draw loop.

---

<div class="post-metadata">

**Author:** ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)\
**Post date:** [March 2, 2021, 10:30am UTC](https://discourse.processing.org/t/select-random-element-from-list/28178/7 "2021-03-02T10:30:28Z")

</div>

@Criste44 Are you coding with processing.py or p5.js ?
