Random number generator
Hi, FreeMarker doesn't have a random number generator for some reason so has anyone created one before?
I want to display random posts depending on topic so I can create a more dynamic page.
For instance, I want to pull all posts labelled 'Test' and display 3 of these at random.
I don't think I can do this via JS because I have to call the total number of posts with that label and then generate 3 random numbers within that range, then display those specific posts.
As far as my admittedly limited experience with JS goes, because all of this happens server side the JS can't run at the correct point in this sequence.
I found this random number generator: http://freestyle-developments.co.uk/blog/?p=327 which does work but only to a point, in that it's not entirely random, if you use a range of 1 to 10 and run it 10 times, almost half return 1 so I don't think it's accurate at all. Even if you put in a range of 1 to 25000 you still get 1 almost every other time.
All I want is something similar to JS Math.random(min, max) but can't find a simple way of doing this at all.
Can anyone help?
Thanks
The utils object has some utilities for generating random numbers. Try utils.numbers.randomIntWithCeiling(ceiling)