- Browse other questions tagged python list python-3.x random python-3.5 or ask your own question .
- As @Tagc says you do range(num – 1) instead of range(num) .
- I am working on a game where I need to randomly generate classes for a list.
- You can correct the issue by changing for i in range(num – 1) to for i in range(num) in your randList function.
- def randList(options, num): #RANDOMLY SELECTS NUM ITEMS FROM LIST OPTIONS returnVal =  #CREATE A LIST THAT IT RETURNS for i in range(num – 1): #FOR DESIRED NUMBER OF RETURN ITEMS val = r.choice(options) #RANDOMLY SELECT ITEM FROM OPTIONS returnVal.append(val) #ADD THAT TO RETURNVAL options.remove(val) #REMOVE IT FROM OPTIONS. return returnVal #RETURN GENERATED LIST
I am working on a game where I need to randomly generate classes for a list. I use a self-made function randList to do this. The code for that function looks like this:
@ng_real_ninja: Random List Generation not working #angularjs #reactjs
, etc. are defined earlier in the code. I don’t think they have anything to do with the problem. I generate the room later like this:
. There are no errors in the code, and after trying to troubleshoot for 10 minutes, I decided to consult he web with no fruits in result of that labor. Thank you in advance for any help you give.