# Can I generate a random number within a range?

**URL:** <https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238>\
**Category:** Uncategorized\
**Created:** [November 6, 2019, 2:23pm UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238 "2019-11-06T14:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SgtIria](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/sgtiria/32/85_2.png) [@SgtIria](https://zola.discourse.group/u/SgtIria)\
**Post date:** [November 6, 2019, 2:23pm UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238/1 "2019-11-06T14:23:31Z")

</div>

I have a need to pick a ‘sudo’ random number from 1-10 in my **Tera** templates. I’ve looked at a bunch of things and cannot find anything obvious to help me so I thought I would ask here.

Anyone come across a solution for this, I did think about using `now() | date(format="%.2f")` and format date to get nano seconds and try something with that. But before I set off on that I thought I would ask here for an approach.

EDIT: Ok a short time later…

tried this:

```auto
{% for p in range(end=10) %}
number: {{ now() | date(format="%2f") }} <br>
{% endfor %}

```

And I get thread panics at a display implementation Error 5 and a whole bunch of stuff? if this not safe?

Thanks

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [November 6, 2019, 5:27pm UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238/2 "2019-11-06T17:27:30Z")

</div>

> [@SgtIria](#):
>
> And I get thread panics at a display implementation Error 5 and a whole bunch of stuff? if this not safe?

Looks like a bug!

---

<div class="post-metadata">

**Author:** ![SgtIria](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/sgtiria/32/85_2.png) [@SgtIria](https://zola.discourse.group/u/SgtIria)\
**Post date:** [November 6, 2019, 5:56pm UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238/3 "2019-11-06T17:56:01Z")

</div>

OK thanks for looking at it.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [November 6, 2019, 11:20pm UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238/4 "2019-11-06T23:20:41Z")

</div>

It looks like a bug in chrono itself. `%2f` doesn’t exist, there is `3f`, `6f`, `9f` and it just panics at runtime when trying to format an unknown format apparently?

Found it: [https://github.com/chronotope/chrono/issues/47](https://github.com/chronotope/chrono/issues/47)  
It’s now fixed in Tera and will be in the next Zola version.

---

<div class="post-metadata">

**Author:** ![SgtIria](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/sgtiria/32/85_2.png) [@SgtIria](https://zola.discourse.group/u/SgtIria)\
**Post date:** [November 7, 2019, 7:34am UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238/5 "2019-11-07T07:34:51Z")

</div>

OK thanks not much I can do about that. I will think about it.

---

<div class="post-metadata">

**Author:** ![SgtIria](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/sgtiria/32/85_2.png) [@SgtIria](https://zola.discourse.group/u/SgtIria)\
**Post date:** [November 12, 2019, 8:17am UTC](https://zola.discourse.group/t/can-i-generate-a-random-number-within-a-range/238/6 "2019-11-12T08:17:15Z")

</div>

I raised this on Tera git as a [requested enhancement](https://github.com/Keats/tera/issues/462). Seemed to be more appropriate. I could not find a sensible way of doing this without having something like the the Jina2 equivalent `random(seq)` template function.
