12

I need to assign a variable which will be used to create the id label for some html elements.

And it needs to be unique.

I tried

{assign var=unique_id value=`10|mt_rand:20`}

and

{math equation='rand(10,100)'}

But I don't know how to use the result

I don't have any other ideas

Daniel Luca CleanUnicorn
  • 1,087
  • 1
  • 12
  • 30

2 Answers2

24

this is how you set and use a random value but that deoesn't mean it will be unique.

    {assign var=unique_id value=10|mt_rand:20}
    {$unique_id}

can you describe a bigger picture of what your doing ?

mcgrailm
  • 17,469
  • 22
  • 83
  • 129
0

I wrote an little Smarty plugin some years ago: https://www.markus.zierhut.name/2010/05/21/php-mit-smarty-zufallszahl-erzeugen/

It's a bit easier to use than handling with mt_rand inside the assign-function. And it keeps compatible with the split of Model and View.

asdfklgash
  • 35
  • 6