# Assigning a random number to a tag on a button click

**URL:** <https://forum.inductiveautomation.com/t/assigning-a-random-number-to-a-tag-on-a-button-click/15115>\
**Category:** General Discussion\
**Created:** [August 20, 2017, 3:15am UTC](https://forum.inductiveautomation.com/t/assigning-a-random-number-to-a-tag-on-a-button-click/15115 "2017-08-20T03:15:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pam3636](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pam3636](https://forum.inductiveautomation.com/u/Pam3636)\
**Post date:** [August 20, 2017, 3:15am UTC](https://forum.inductiveautomation.com/t/assigning-a-random-number-to-a-tag-on-a-button-click/15115/1 "2017-08-20T03:15:04Z")

</div>

As the topic suggests, on a button click I would like to assign a random number to a tag:

value = random.randint(1, 52)  
system.tag.write(‘MyTag[0]’, value)

but I obviously need to change the syntax in line 1. Is there something I can do in ignition to achieve this?

Thank you!

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [August 20, 2017, 6:37am UTC](https://forum.inductiveautomation.com/t/assigning-a-random-number-to-a-tag-on-a-button-click/15115/2 "2017-08-20T06:37:06Z")

</div>

You need to import random first.

```auto
import random
value = random.randint(1, 52)
system.tag.write('MyTag[0]', value)

```

---

<div class="post-metadata">

**Author:** ![Pam3636](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pam3636](https://forum.inductiveautomation.com/u/Pam3636)\
**Post date:** [August 20, 2017, 1:17pm UTC](https://forum.inductiveautomation.com/t/assigning-a-random-number-to-a-tag-on-a-button-click/15115/3 "2017-08-20T13:17:07Z")

</div>

boom that’s how it is done. Thank you!
