FreeMarker doesn’t have a random number generator function. I needed a really simple solution that would allow me to pick a random image URL to be displayed on the homepage.
<#--
* Generates a "random" integer between min and max (inclusive)
*
* Note the values this function returns are based on the current
* second the function is called and thus are highly deterministic
* and SHOULD NOT be used for anything other than inconsequential
* purposes, such as picking a random image to display.
-->
<#function rand min max>
<#local now = .now?long?c />
<#local randomNum = _rand +
("0." + now?substring(now?length-1) + now?substring(now?length-2))?number />
<#if (randomNum > 1)>
<#assign _rand = randomNum % 1 />
<#else>
<#assign _rand = randomNum />
</#if>
<#return (min + ((max - min) * _rand))?round />
</#function>
<#assign _rand = 0.36 />
I’ve added this function to the FreeMarker Spring extensions I’ve been building up. You might use it in your code like so:
<img src="<@spring.url "/images/" + springx.rand(1, 10) + ".jpg" />" />
Note that there are obvious issues with this function. Aside from being based heavily on the second the function is called, you’ll notice that the min and max have less probability of being generated as the other values…what? I said it was simple.
http://beer4billy.com/author/woodenxsh83/
certainly like your web site however you have to test the spelling on quite a few of your posts. Several of them are rife with spelling problems and I find it very bothersome to inform the truth then again I will definitely come back again.
Most of our clients report clearer increases in leads and sales once they start receiving keyword- and location-targeted traffic. Vantovo’s AI matches visitors from a partner network and improves every day. You can test it risk-free for 7 days and cancel at any time.
Get more information and start your free trial here: https://clck.ru/3WHETT
https://www.lemongrovelane.com/author/regardingtfr1914/
нанять разработчика смарт контрактов ochered-u-ekrana.site web разработка заказать
https://hutsons-hacks.info/author/toescq09/
https://hutsons-hacks.info/author/toescq09/
как создать кошелек для криптовалюты ochered-u-ekrana.site разработка blockchain
https://www.lemongrovelane.com/author/regardingtfr1914/
https://hutsons-hacks.info/author/toescq09/
создать криптообменник ochered-u-ekrana.site разработка криптобиржи
https://medibulletin.com/author/remarkjwd859/
услуги frontend разработчика ochered-u-ekrana.site блокчейн решения для бизнеса
https://medibulletin.com/author/remarkjwd859/