How to get a random number in JSTL?

el, jsp, jstl

Solution

This one is a bit ugly but it works...

<c:set var="rand"><%= java.lang.Math.round(java.lang.Math.random() * 2) %></c:set>

Later you can check for `${rand mod 2 == 0}` and `${rand mod 2 == 1}` to get your desired output.

Problem

I would like to get something like the next code generated in JSTL ``` <c:choose> <c:when test="${random number is even}"> <div class="redlogo"> </c:when> <c:otherwise> <div class="greenlogo"> </c:otherwise> </c:choose> ```

Original source