Assigning a random number to a tag on a button click

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!

1 Like

You need to import random first.

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

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