能否在上产生随机的分类?
I m trying to implement a weighted random numbers. I m currently just banging my head against the wall and cannot figure this out. In my project (Hold em hand-ranges, subjective all-in equity ...
能否在上产生随机的分类?
Freemarker does not provide a random number generator at the moment. You can implement a naive random number generator using the time ( .now ) as a seed, but it should never be a critical part of your program.
你可以在 Java产生随机的愤怒,并将这种愤怒传递给自由标识模板。
正如Kayhadrin所建议的那样,这里简单地采用随机生成。 如果我实际工作,我没有时间进行测试,但也许会帮助他人。
http://v01ver-howto.blogspot.fi/07/howto-generate-random-integer-in.html
另一种选择是创建自己的Freemarkermeth,并将其注入数据模型。
这方面的一个例子是 Java8如何做到这一点:
public String generate(Map<String, Object> data, String templateLocation) throws IOException, TemplateException {
try (StringWriter writer = new StringWriter()) {
Template template = configuration.getTemplate(templateLocation);
data.put("uuid", (TemplateMethodModelEx) (list) -> UUID.randomUUID());
Random r = new Random();
// Adding method for generation of random number
data.put("randomNumber", (TemplateMethodModelEx) (list) -> r.nextInt(200));
template.process(data, writer);
return writer.toString();
}
}
在“自由标识”模板中,你将能够使用这种方法:
${randomNumber()}
我只是把一个相对随机的生成器放在一起。 采用<代码>.now?long的微秒,并用你的种子(salt)加以多倍。 (就第7条而言)和三者之间的差距。 在我的案件中,我只需要5个数字,但每天可以达到每秒13位数。 或者说,如果你想增加更多的乘数、增加数等等的话。
<#function randomNumber salt>
<#local str= .now?long />
<#assign str = (str * salt)/3 />
<#return str[(str?string?length-5)..]/>
</#function>
<#assign rnd = randomNumber(7)/>
如果你不想要salt,你就只能删除计算中的参数和硬代码salt变量和仅打电话randomNumber(
。
Let s say you want to add a random image out of some set to each listed item. So get a seed, and then rotate that seed in some way.
<#assign photos>
DSC_0005.jpg
DSC_0008.jpg
DSC_0013.jpg
DSC_0020.jpg
</#assign>
<#assign photos = photos?split( \n , rmc ) >
<#assign nextRandom = .now?string["HHmmssSSS"]?number>
<#list posts as post>
<div class="banner divider" style="background-image: url(photos/panoramas/${photos[nextRandom % photos?size]});"></div>
<#assign nextRandom = nextRandom * 13 % 104729>
</#list>
我选择了<代码>nextRandom = 下一个Random * 13 % 104729,但我必须从统计角度讲,这非常不是原则。 还确保104729人比你收集的钱多。
更好的办法,至少对于超文本处理,是把这种收集工作带往 Java,并从那里收集:
<script type="text/javascript">
var photos = [ <#list photos as photo> ${photo} , </#list> ];
var randomPhoto = photos[Math.floor(photos.length * Math.random())];
</script>
See e.g. Math.random( at MDN.
I m trying to implement a weighted random numbers. I m currently just banging my head against the wall and cannot figure this out. In my project (Hold em hand-ranges, subjective all-in equity ...
There are a lot of questions about salts and best practices, however most of them simply answer very specific questions about them. I have several questions which feed into one another. Assuming a ...
I am working on a php site in which we have to upload images from users.i have to rename that file for preventing conflicts in the name of the image. uniqid(rand(), true); and adding a large random ...
How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.
According to various sources, such as Wikipedia and various .edu websites found by Google, the most common ways for a hash table to resolve collisions are linear or quadratic probing and chaining. ...
I m pulling my hair out trying to build a little random photo JSON feed using DataMapper/Sinatra. Here s what I have so far.. Photo.favorites.to_json(:methods => [:foo, :bar]) So that works fine. ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I have two animation sequences, and I want one of them to play randomly when a button is pressed. Here is the code: { color.animationImages = [NSArray arrayWithObjects: [...