Lottery

02/18/2014 11:11 InsomniacPro#1
So I'm in the process of coding a lottery system. The problem I'm having is that I can only think of a way to pick items at completely random. I can't figure out how to pick an item on chance. Basically all I'm doing is picking a group of entries with all the same chance value, and picking an item out of there. This is working completely random instead of chance so it kind of messes it up and beefs up the lotto. Any suggestions?
02/18/2014 12:31 abdoumatrix#2
try something like this i used for using random spell


most sources use list
02/18/2014 12:31 Aceking#3
Well create a chance method.

Have the chance percent as an argument, then perform your random calculations, and return if it was a success or failure.
Almost every source in the released section has one of these systems, take a look.
Should be rather easy to create one yourself.
02/18/2014 17:23 Super Aids#4
Something like this?
Code:
	ConquerItem SelectItem()
	{
		while (true)
		{
			foreach (byte key; in m_lotteryItems.keys) // ConquerItemCollection[byte] m_lotteryItems;
			{
				import dconquer.calculations;
				if (ChanceSuccess(key))
					return new ConquerItem(m_lotteryItems[key].SelectRandomItem());
			}
		}
		return null;
	}
ChanceSuccess:
Code:
bool ChanceSuccess(byte chance)
{
	import std.random;
	import dconquer.core.generators;

	if (chance >= 100)
		return true;
	auto rn = uniform(0, chance, RandomGenerator);
        return (rn < chance);
}
02/19/2014 04:18 Y u k i#5
a while(true) loop without a sleep? Fishy.
02/19/2014 05:15 Spirited#6
Quote:
Originally Posted by Y u k i View Post
a while(true) loop without a sleep? Fishy.
It's also written in D, hinting he's working on a conquer online server source written in D.
02/19/2014 05:23 _DreadNought_#7
Quote:
Originally Posted by Spirited Fang View Post
It's also written in D, hinting he's working on a conquer online server source written in D.
Explains my confusion on a couple keywords :P
02/19/2014 17:39 Super Aids#8
@Yuki, if you had a bit common sense you'd figure out that it probably wouldn't run infinite, because the rates on items aren't 0% and that some items might have high rates so it would probably only run 1-3 times.

If it makes you happy this could be used:
Code:
import core.thread;
Thread.sleep(dur!("msecs")( 1 ));
@fang I was, although I've considering writing a new.