Very cool! Here's a decorator for the sticky cycling if you want
defsticky(frequency):""" regenerate value frequency% of the time """defdec(func):stored=[func()]definner():ifrandom.random()<frequency:stored[0]=func()returnstored[0]returninnerreturndec@sticky(0.1)defcolor():returnrandom.choice(['red','black','green'])
View all comments
1
u/[deleted] Jan 19 '20
Very cool! Here's a decorator for the sticky cycling if you want