---
title: "Comment by ZHE ZHANG on \"The Tri-Z Architecture: a Pattern for Layering ZIO Applications in Scala\" | Hashnode"
description: "How to mix Random/Clock(ZIO side effects) with ZPure(pure domain)? While generating some random rewards or properties for equipments in business logic."
url: "https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/677fa9708649df594c2445bf"
---

[Discussion](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731)

Comment [The Tri-Z Architecture: a Pattern for Layering ZIO Applications in Scala](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731)

[ZHE ZHANG](https://hashnode.com/@zhangjiji)

[Jan 9, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/677fa9708649df594c2445bf)

How to mix Random/Clock(ZIO side effects) with ZPure(pure domain)? While generating some random rewards or properties for equipments in business logic.

[Pierre Ricadat](https://hashnode.com/@ghostdogpr)

[Jan 9, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/677fa9708649df594c2445bf#reply-677fac5778b7eabfce0eb273)

Since they return `ZIO`, you can't use them directly. In our case we often include the current time in the environment R (so we get it before running the ZPure and then the value is consistent during the execution since the environment is read-only). For random, we use Scala Random directly wrapped inside `ZPure.suspend`.

[ZHE ZHANG](https://hashnode.com/@zhangjiji)

[Feb 13, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/677fa9708649df594c2445bf#reply-67ad9342e6b0672ff7045137)

I apologize, I'm still a bit confused about the Random part.

I understand it's like defining something like: def nextInt: Program\[Int\] = ZPure.suspend(ZPure.attempt(rng.nextInt()))?

Does using Scala's Random directly lead to a loss of purity? Could you please explain it a bit more concretely? Thank you.

[Pierre Ricadat](https://hashnode.com/@ghostdogpr)

[Feb 13, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/677fa9708649df594c2445bf#reply-67ad9ba2a14d61a28ab25a65)

That's right, that's how we do if we need it. It's non-deterministic but I think it's acceptable since it doesn't cause any actual side effects.
