I also added a Lotto Generator that help me pick Lottery game numbers
If created for the Belgian Lotto but it can easily be adapted
Sitemap
Frame label="Lotto Generator" {
Switch item=LottoState label="Lotto Nummers" mappings=[ON="Pick!"] icon=magic
Text item=Lotto valuecolor=["blue"] visibility=[Lotto!=""] icon=lotto
}
ITEMS
String Lotto "Winnende nummers [%s]" //winning numbers
Switch LottoState
RULES
import java.util.*;
import java.util.List
rule _lotto
when
Item LottoState received command
then
//There are 45 lotto numbers
// each game is 6 numbers
//lotto nrs based on https://www.nationale-loterij.be/onze-spelen/lotto/statistieken from best to worse
//last upadted 3/11/2018
val int[] theLottoNumbers = newArrayList(7,12,16,24,38,22,5,25,28,14,17,33,9,3,13,36,27,2,4,18,19,21,10,29,20,31,1,40,23,6,26,32,35,11,34,37,39,8,41,42,30,15,43,45,44)
//create result arraylist
val List<Integer> result = newArrayList()
//last number in theLottoNumbers to use
var int lastgoodnr = 16
//Pick random nrs and add to result array
while (result.size() < 6) {
var int i = (new java.util.Random).nextInt(lastgoodnr+1)
var int currentNR = theLottoNumbers.get(i)
if (result.size > 0 ) {
if (result.contains(currentNR)) {
//logInfo("Lotto Generator","Duplicate number: " + currentNR.toString())
} else {
result.add(currentNR)
}
} else {
result.add(currentNR)
}
}
//sort the result array
Collections.sort(result)
//add array to string and format string to show always 2 decimals
var String strResult = String.format("%1$02d %2$02d %3$02d %4$02d %5$02d %6$02d",result.get(0),result.get(1),result.get(2),result.get(3),result.get(4),result.get(5))
logInfo("Lotto Generator","Generated Lotto Numbers: " + strResult)
//Show the generated numbers in sitemap
Lotto.postUpdate(strResult)
//hide result after 2 minutes, possible not ideal, because it creates a timer everytime.
createTimer(now.plusMinutes(2), [|
Lotto.postUpdate("")
])