vanlion
February 10, 2019, 10:29am
1
Hi,
I’d like to place random families with Python. I have a working code to place one family type with Python
But my wish is that it picks a random family from the listRandom, so item.Symbol = Random listRandom value or something.
See below code:
Thanks!
Try using a random int to select an item in your list. See here for how to make random numbers…
In your case what you should do is…
item.symbol = listRandom[random.randint(0, len(listRandom)-1]
Make sure you also import random library first.
Also, for the family types, i would import them all as one list called listRandom instead of having a port for each family type. This way, you can have any length of list without having to manually add to listRandom in code.
vanlion
February 10, 2019, 2:08pm
3
Hi,
Thanks for helping.
I’ve done the things you said but i get the unexpected token ] error from your code
You are missing an ‘)’ before the ‘]’ on line 27. When you see this kind of error, it is a good indicator you haven’t closed out with ).
vanlion
February 10, 2019, 2:32pm
5
Daniel_Woodcock1:
random.randint
Thanks, that i didn’t see that :-S
Last question, can you build something in Python that you can make sure it is never uses the same family next to each other?
This is the working solution:
Might i ask what your ‘‘count’’ is accomplishing?