Source code: org/alicebot/server/core/processor/RandomProcessor.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4
5 package org.alicebot.server.core.processor;
6
7 import org.alicebot.server.core.parser.TemplateParser;
8 import org.alicebot.server.core.parser.XMLNode;
9 import org.alicebot.server.core.util.LRUCache;
10 import org.alicebot.server.core.util.MersenneTwisterFast;
11
12 // Referenced classes of package org.alicebot.server.core.processor:
13 // AIMLProcessor, AIMLProcessorException
14
15 public class RandomProcessor extends AIMLProcessor
16 {
17
18 public RandomProcessor()
19 {
20 }
21
22 public String process(int i, XMLNode xmlnode, TemplateParser templateparser)
23 throws AIMLProcessorException
24 {
25 if(xmlnode.XMLType == 0)
26 {
27 if(xmlnode.XMLChild == null)
28 return "";
29 String s = templateparser.getBotID() + templateparser.getUserID() + xmlnode.toString();
30 MersenneTwisterFast mersennetwisterfast = (MersenneTwisterFast)generators.get(s);
31 if(mersennetwisterfast == null)
32 {
33 mersennetwisterfast = new MersenneTwisterFast(System.currentTimeMillis());
34 generators.put(s, mersennetwisterfast);
35 }
36 int j = templateparser.nodeCount("li", xmlnode.XMLChild, false);
37 if(j == 0)
38 return "";
39 if(j == 1)
40 return templateparser.evaluate(i++, templateparser.getNode("li", xmlnode.XMLChild, 1).XMLChild);
41 else
42 return templateparser.evaluate(i++, templateparser.getNode("li", xmlnode.XMLChild, mersennetwisterfast.nextInt(j) + 1).XMLChild);
43 } else
44 {
45 throw new AIMLProcessorException("<random></random> must have content!");
46 }
47 }
48
49 public static final String label = "random";
50 private static final String LI = "li";
51 private static final LRUCache generators = new LRUCache(100);
52
53 }