comp.lang.ada
 help / color / mirror / Atom feed
* Re: help with random number
  2000-11-13  5:01 help with random number mountainman
@ 2000-11-13  0:00 ` Robert Dewar
  2000-11-13  0:00 ` Pascal Obry
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 2000-11-13  0:00 UTC (permalink / raw)


In article <5ltu0to0o3mt8c9liev26229n9mnhi0rvu@4ax.com>,
  mountainman wrote:
>. Like a card game I need it to pull an Ace of Spades only
> once till the game is over.  Any help would be very
> appreciated.


This is a very standard beginning programming assignment
(shuffling a deck of cards).

Don't look for a built in random number generator to do this,
that's not the point of the excercise.

Instead, think about how you could use perfect coin tosses
to shuffle a deck, or think about how, when there are 37
cards left, you choose a random one of the cards left.



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: help with random number
  2000-11-13  5:01 help with random number mountainman
  2000-11-13  0:00 ` Robert Dewar
@ 2000-11-13  0:00 ` Pascal Obry
  1 sibling, 0 replies; 3+ messages in thread
From: Pascal Obry @ 2000-11-13  0:00 UTC (permalink / raw)



mountainman <mountainman@123.net> writes:

> Hello to all of you smart people out there. I need some help. Im
> trying to create a random number generator that will only pull a
> specific number once and not repeat till told to do so. Im using an
> example I found on the net and it works great. I just dont know what
> to do to tell it not to pull the same number a second time untill i
> can reset it. Like a card game I need it to pull an Ace of Spades only
> once till the game is over.  Any help would be very appreciated.
> Thanks

What you want is a suite of Card, the cards on the deck are shuffled (so not
ordered), each one must be picked only once.

1)  Have a boolean associated with a card to tell if it has already been
    picked. Here you use the random generator to pick a card (not very
    efficient).

2)  Build an array of cards then swap 2 cards randomly many times, this will
    give you a shuffled cards deck (well an array of card :). Here you use the
    random generator to shuffle the cards.

3)  <put your own design here>

Pascal.

-- 

--|------------------------------------------------------------
--| Pascal Obry                               Team-Ada Member |
--|                                                           |
--| EDF-DER-IPN-SID- T T I                                    |
--|                       Intranet: http://cln46gb            |
--| Bureau N-023            e-mail: p.obry@der.edf.fr         |
--| 1 Av G�n�ral de Gaulle  voice : +33-1-47.65.50.91         |
--| 92141 Clamart CEDEX     fax   : +33-1-47.65.50.07         |
--| FRANCE                                                    |
--|------------------------------------------------------------
--|
--|         http://perso.wanadoo.fr/pascal.obry
--|
--|   "The best way to travel is by means of imagination"




^ permalink raw reply	[flat|nested] 3+ messages in thread

* help with random number
@ 2000-11-13  5:01 mountainman
  2000-11-13  0:00 ` Robert Dewar
  2000-11-13  0:00 ` Pascal Obry
  0 siblings, 2 replies; 3+ messages in thread
From: mountainman @ 2000-11-13  5:01 UTC (permalink / raw)


Hello to all of you smart people out there. I need some help. Im
trying to create a random number generator that will only pull a
specific number once and not repeat till told to do so. Im using an
example I found on the net and it works great. I just dont know what
to do to tell it not to pull the same number a second time untill i
can reset it. Like a card game I need it to pull an Ace of Spades only
once till the game is over.  Any help would be very appreciated.
Thanks




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-11-13  5:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-13  5:01 help with random number mountainman
2000-11-13  0:00 ` Robert Dewar
2000-11-13  0:00 ` Pascal Obry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox