Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Generate random number

Avatar

Level 8
Level 8
Hi all,



Does anyone know how I can generate a random number?



My idea is that I can create a loop for handling the indexes of a string one by one, but I don't know if it is possible to get a single random number.



Of course I could create my own custom service as well, but I would like to use the stand alone services first and fore most if it is possible.



Is it possible without a custom service?



Thanks in advance



Sincerely

Kim
2 Replies

Avatar

Former Community Member
There are functions in Javascript for this. Did a search on the web and come up with this one:



var num=Math.floor(Math.random()*1000)



Where num will contain a random number between 0 and 1000. If you want a different range change the 1000 to your max range.

Avatar

Level 8
Level 8
Thanks a lot Paul, that is very usefull, allthough I would have liked it to be possible without using the script-service.



Thanks again, I really appreciate it



Sincerely

Kim