Velocity - random number generation in a template
问题 I'd like to assign a random value to a variable in a velocity template. However, #set ($random = $math.getRandom()) returns: java.util.Random@5706937e. How to obtain this value or assign a random value to a variable in a different way from within a velocity template? 回答1: #set ($random = $math.getRandom()) use velocity 1.7 from this link enter link description here and in vm file use #set($mathTool = $serviceLocator.findService("org.apache.velocity.tools.generic.MathTool")) //range: 1 - 20