Marc Cawood
 · Positivity ✌️

Expression to get random element of array

I want an expression to return a random element of an array - in this case either "men" or "women".

Since there is no random number generator, I just use the sin function on the current time.

This gives a nice random 0 or 1.

now|to_seconds|sin|add:1|floor

When I run ["women", "men"][now|to_seconds|sin|add:1|floor] I would expect to get either "men" or "women" but I get ["women", "men"]

Why does:

  • ["women", "men"][0] return "women" ✅

  • ["women", "men"][1] return "men" ✅

  • ["women", "men"][now|to_seconds|sin|add:1|floor] return ["women", "men"] the original array?? ❌

4 replies