# Smart way of creating a random sample for process instances?

**URL:** <https://forum.camunda.io/t/smart-way-of-creating-a-random-sample-for-process-instances/55437>\
**Category:** Discussion & Questions\
**Created:** [September 25, 2024, 12:03pm UTC](https://forum.camunda.io/t/smart-way-of-creating-a-random-sample-for-process-instances/55437 "2024-09-25T12:03:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius\_b](https://forum.camunda.io/letter_avatar_proxy/v4/letter/m/858c86/32.png) [@marius\_b](https://forum.camunda.io/u/marius_b)\
**Post date:** [September 25, 2024, 12:03pm UTC](https://forum.camunda.io/t/smart-way-of-creating-a-random-sample-for-process-instances/55437/1 "2024-09-25T12:03:37Z")

</div>

Hi everyone,

i am currently building a process in which x% of process instances need to be reviewed in a user task. Imagine something like shown in the screenshot:

 ![Bildschirmfoto 2024-09-25 um 13.39.46](https://forum.camunda.io/uploads/default/original/3X/7/8/78084f27d0de34aac365d60b634b87e93ed52fa4.png)

Now my first guess is to just define a service task that marks a process instance with a probability of X% by adding a variable like “sample: true” to the process instance.

However, I am asking myself if there is a smarter way to do such a randomized sampling in Camunda?

Edit: I forgot to mention that currently I am working in Camunda 7 🙂

Best regards

---

<div class="post-metadata">

**Author:** ![Niall](https://forum.camunda.io/user_avatar/forum.camunda.io/niall/32/15333_2.png) [@Niall](https://forum.camunda.io/u/Niall)\
**Post date:** [September 25, 2024, 12:41pm UTC](https://forum.camunda.io/t/smart-way-of-creating-a-random-sample-for-process-instances/55437/2 "2024-09-25T12:41:33Z")

</div>

Might be easier to an expression to one of the squence flows which returns true ~x% of the time. Then have the other sequence flow be the defult flow.

In javascript, if you wanted something to return true 25% of the times it would eb something like

```auto
 Math.random() < 0.25 

```

---

<div class="post-metadata">

**Author:** ![marius\_b](https://forum.camunda.io/letter_avatar_proxy/v4/letter/m/858c86/32.png) [@marius\_b](https://forum.camunda.io/u/marius_b)\
**Post date:** [September 26, 2024, 8:56am UTC](https://forum.camunda.io/t/smart-way-of-creating-a-random-sample-for-process-instances/55437/3 "2024-09-26T08:56:34Z")

</div>

Hi @Niall ,  
thanks for your reply! I managed to get to the goal by changing my diagram as suggest by you:

 ![Bildschirmfoto 2024-09-26 um 10.56.13](https://forum.camunda.io/uploads/default/original/3X/0/8/083e7138a48b972c51821f7ad6a7381a0e5ed537.png)

Best regards

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [October 3, 2024, 8:57am UTC](https://forum.camunda.io/t/smart-way-of-creating-a-random-sample-for-process-instances/55437/4 "2024-10-03T08:57:13Z")

</div>

Closed on October 3, 2024, 8:57am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
