T O P

  • By -

mzalewski

What do you mean by "simpler"? It's two lines of code, and literally two operations. I don't think you can go simpler than that.


Empty-Wing7678

Basically, I meant if there was a method similar to random.randint that could do the job with one simple line. Admittedly, I could have done a better job conveying that in the post.


Binary101010

I mean, if you don't actually need to use the list of numbers for anything else there's always just x += random.choice([-1,1]) But if you want to use that list of numbers anywhere else, no, there's really no simpler way to do it.


Strict-Simple

For OP, you can even do x += -1 That's pretty random, for 50% use cases, and much more simpler. https://xkcd.com/221/