# How to calculate random no

**URL:** <https://discuss.elastic.co/t/how-to-calculate-random-no/113884>\
**Category:** Logstash\
**Created:** [January 3, 2018, 7:26am UTC](https://discuss.elastic.co/t/how-to-calculate-random-no/113884 "2018-01-03T07:26:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shekhar\_Pandey](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shekhar\_Pandey](https://discuss.elastic.co/u/Shekhar_Pandey)\
**Post date:** [January 3, 2018, 7:26am UTC](https://discuss.elastic.co/t/how-to-calculate-random-no/113884/1 "2018-01-03T07:26:58Z")

</div>

hello..

Anybody know how to generate random numbers between 0 to .5 using logstash.  
I use the following code but not working..

ruby {  
code =\> 'event.set("randomNumber", rand(100).to\_i())'  
}

Thanks

---

<div class="post-metadata">

**Author:** ![Shekhar\_Pandey](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shekhar\_Pandey](https://discuss.elastic.co/u/Shekhar_Pandey)\
**Post date:** [January 3, 2018, 9:06am UTC](https://discuss.elastic.co/t/how-to-calculate-random-no/113884/2 "2018-01-03T09:06:46Z")

</div>

I solved my problem...

Here is solution so anybody can use this...

filter{  
ruby {  
code =\> 'event.set("randomNumber", ((rand() \*0.9).to\_f))'

```
}

```

}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 31, 2018, 9:07am UTC](https://discuss.elastic.co/t/how-to-calculate-random-no/113884/3 "2018-01-31T09:07:50Z")

</div>

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