I know we recently had a thread dealing with randomness (shuffling a deck).
The consensus seemed to be to sweep that issue under the rug and try to
test around it.
What if randomness is an integral part of your code? For example, say that
you want to play a sound from a set at random when a certain event happens.
Take it further and say that the user can select the different sounds and
the probability of each sound being played. How do you use TDD for
something like that?
Sure, you can test that when I set the probability to 1 and another to 0,
the sound with probability 1 gets played. But how do I test the situation
where I have two sounds one with probability 0.8 and the other one 0.2? I
would really prefer not to call the event X times and get a sampling that
way, but right now it's the best idea I can think of.
I know we recently had a thread dealing with randomness (shuffling a deck). The consensus seemed to be to sweep that issue under the rug and try to test around...
... If I had an RNG that I trusted, I'd roll 0 <= x < 1 and select based on x < 20, and would be unlikely to test that further, other than perhaps once by...
... Well, my eyeball says I meant x < 0.20 ... :) Ron Jeffries www.XProgramming.com There is economic value in manufacturing identical wheels. There is no ...
I think I would go a different way... I'd possibly write a test for the RNG, testing that it produces random results, if necessary, or use someone else's RNG...
Michael Brunton-Spall
michael.brunton-spall...
Feb 22, 2005 11:00 am
... At first reaction, I like that. Ron Jeffries www.XProgramming.com It is not the strongest of the species that survive, not the most intelligent, but the...
Phlip: "One TDDs generic randomness by replacing rand() with a mock object." What test did you write that drove you to introduce rand() in the first place? I...
... Uh, little secret: Sometimes in TDD you write half the test, then write a little code, then finish the test. Sometimes. The goal is staying in absolute...
That's a perfectly valid random sequence. As is 0,1,3,2,4,5.. And so on. The same as you just as likely to win with a Lottery ticket with the numbers...
Michael Brunton-Spall
michael.brunton-spall...
Feb 23, 2005 2:44 pm
... You flip a coin and get heads 5 times. What are the odds of the 6th flip turning up heads? The odds of having a bomb on board your plane are a billion to...
The odds of a 6th flip turning up heads is 1 in 2. The odds of a single flip is 50% heads, 50% tails (obviously that's not actually true, odds vary depending...
Michael Brunton-Spall
michael.brunton-spall...
Feb 23, 2005 3:15 pm
It's bad enough we're still on this subject; don't get us off onto the Let's Make a Deal thread now, too! :-p - Brad...
Yeh sorry. I've got Thursday and Friday off to go to London, so it's almost like Friday afternoon for me at the moment :) Thanks for the name of the show I...
Michael Brunton-Spall
michael.brunton-spall...
Feb 23, 2005 3:52 pm
... (snip) ... What are the odds of that? (sorry, I couldn't resist) Doug...
... Because I was bored, I wrote a little JUnit test for java.util.Random. I cheated a little, instead of 2/10, I used 1/5. It took me 16 minutes to write the...
... Nods! Here is an article deals a bit with that subject. "Randomness without Replacement" http://www.gamedev.net/reference/design/features/randomness/ ...
... Sorta, yes. Not sweep the issue under the rug, but rather isolate the randomness and test all the deterministic components. ... The shuffling example was...
... I don't think you can TDD a better RNG by testing for randomness. I think you'd do better to hire a mathemetician and TDD conformance to the algorithm. If...
As far as randomness goes, you can't test for it - it's not a well-defined concept (I remember spending a whole semester in grad school proving that nomatter...
... "Anyone who considers arithmetical methods of random digits is, of course, in a state of sin." -- John von Neumann (quoted in Knuth, Vol.2) Knuth's...
... I have to point out that this is a straw man. In cases where some sort of provable randomness is needed, e.g. for cryptographic algorithms, you come up...
... No, but you can *measure* certain aspects to compare the quality of different random sequences. Basically, as I recall, it comes down to checking it in...
... "Did you listen to a word I said?" "You said 'flip'! Hur, Hur, Hur, <snigger>" (Sorry, I recently watched some of "100 greatest cartoons", which showed a ...