tags:

views:

105

answers:

3

Dear Friends !

I have very definitively come across the 'simulating a 6-faced die' (which produces a random integer between 1 and 6, all outcomes are equally probable) in Java, Python, Ruby and Bash. However, I am yet to see a similar program in Ada. Has anyone come across one ?

Kind regards

Arkapravo

+2  A: 

With Ada 95, a random number generator was defined as part of the standard library making it a required component of every Ada 95 compilation system.

Therefore, yes you can simulate a 6-faced die in Ada quite easily.

Mitch Wheat
That's probably why he hasn't come across such a thing. It would be too trivial to bother with.
T.E.D.
Could be, T.E.D ..... however, most surprisingly, I have not even come across any sort of stochastic structure being programmed in Ada.
Arkapravo
Don't know what to tell you, dude. One of the first things I ever coded in Ada back in 1989 was a random number generator. Sadly, I took the algorithm from a textbook and didn't really investigate the effect that the interface I provided for it had on the algorithim. It turned out that if you asked for a random value with a suitably small range (I think it was 0-3), it alternated between two results. This is why it is best to leave such things to the experts. :-)
T.E.D.
Phew ! ..... seems Ada did some parallel processing in randomisation too .... T.E.D, if you do find that program then please do send it across ! ... :)
Arkapravo
+2  A: 

See Random Number Generation (LRM A.5.2) for packages to assist with doing this. Either Ada.Numerics.Float_Random for uniform random number generation (range 0.0 .. 1.0) which you can then scale on your own, or instantiate Ada.Numerics.Discrete_Random with a suitable (sub)type (works for d4, d10, d12, and d20s as well!).

Marc C
Thanks ! ..... LRM is THE BIBLE !
Arkapravo
+2  A: 

You might enjoy this simulation of the children's card game of war.

trashgod