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>
To generate a random number in Swift, use Int. random() function. Int. random() returns a number, that is randomly selected, in the given range.
Math.random() The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With