Shopify Flow: Run Code does not understand Math.random()

Topic summary

  • Main issue: In Shopify Flow’s “Run Code” action (JavaScript), Math.random() returns the same float on every execution: 0.8549251903236059.
  • Clarification: A responder cites Shopify’s official documentation on Run Code limitations. Random number generation is intentionally restricted, causing Math.random() to be non-functional for true randomness.
  • Rationale: The restriction exists to prevent abuse such as crypto mining in the execution environment.
  • Outcome: The report is not a bug; it’s expected behavior per Shopify docs.
  • Resolution/next steps: No workaround or alternative solution was discussed. The original poster acknowledged the explanation.
  • Status: Settled from a community perspective; the behavior is by design, with no indicated change planned.
Summarized with AI on December 18. AI used: gpt-5.

In Shopify Flow, when using the action node ‘Run Code’ (used to run JavaScript), if I try to generate a random float with Math.random(), for some reason it always returns the same float on every single attempt: 0.8549251903236059

Is this a known issue?

See https://help.shopify.com/en/manual/shopify-flow/reference/actions/run-code#limitations

It’s blocked on purpose to prevent crypto mining.

1 Like

That is unfortunate to hear. Thanks for letting me know Paul