Click here to Skip to main content
16,016,537 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Another random number generator Pin
ChandraRam1-Dec-07 7:32
ChandraRam1-Dec-07 7:32 
AnswerRe: Another random number generator Pin
cp987625-Nov-07 23:44
cp987625-Nov-07 23:44 
GeneralRe: Another random number generator Pin
ChandraRam25-Nov-07 23:54
ChandraRam25-Nov-07 23:54 
GeneralRe: Another random number generator Pin
cp987626-Nov-07 0:42
cp987626-Nov-07 0:42 
GeneralRe: Another random number generator Pin
ChandraRam26-Nov-07 0:46
ChandraRam26-Nov-07 0:46 
GeneralRe: Another random number generator Pin
cp987626-Nov-07 0:51
cp987626-Nov-07 0:51 
GeneralRe: Another random number generator Pin
ChandraRam26-Nov-07 0:54
ChandraRam26-Nov-07 0:54 
GeneralRe: Another random number generator Pin
Mark Churchill19-Dec-07 15:10
Mark Churchill19-Dec-07 15:10 
What is the application for this? It's not going to come out very random with these constraints Wink | ;)

I'd do something like this:

Its not going to win any awards for neatness, but I think it uses fairly minimal memory. Also its generating the numbers on the fly, rather than using a pre-sorted array, which is kindof cheating Wink | ;)

IEnumerable< int > ChandrasCrazyNumbers()
{
   // We use dictionarys like lists (string, bool) because this lets us
 use the hash-backed index to do removes. The bool is always true - its 
a placeholder.

   // I've kinda expanded this out into ones, tens, hundreds because 
when its more generalised it gets harder to follow.

   Dictionary< string, bool> ones = 
   Dictionary< string, Dictionary< string, bool>> tens =
   Dictionary< string, List< string >> hundreds =
   Dictionary< string, List< string >> thousands =


   // now we will first pick the rightmost random digit from the ones list
   // and remove it from the avaliable ones... say "4"
   // then pick an avaliable tens that corresponds to the ones, say "24"
   // etc etc

while(true)
{
initialise thousands like so: iterate 0-9999, for say 5983, file that under
"983", {... {"5983", true} .... } 
while(thousands.Count > 0)
{
initialise hundreds like so: iterate 0-999, for say 583, file that under
"83", {... {"583", true} .... } 
while(hundreds.Count >0)
{
 initialise tens like so: iterate 0-99, for say 58, file that under
      "8", {... {"58", true} .... }
   while(tens.Count > 0)
   {      
       init ones like so: {"0", "1"... "9"} all true;
       while(ones.Count > 0)
       {
          string randomOne = ones.Keys[random between 0 and ones.Count)];
          ones.Remove[randomOne];

          string randomTen = tens[randomOne].Keys[random between 0 and tens.Count)];
          tens.Remove[randomTen];

          // ditto for hundreds and thousands

          yield return int.Parse(string.Concat(...., randomTen, randomOne));
       }
   }
}}}}}


GeneralRe: Another random number generator Pin
ChandraRam19-Dec-07 18:58
ChandraRam19-Dec-07 18:58 
QuestionEM algorithm Pin
yanhe011615-Nov-07 12:11
yanhe011615-Nov-07 12:11 
AnswerRe: EM algorithm Pin
Luc Pattyn15-Nov-07 12:19
sitebuilderLuc Pattyn15-Nov-07 12:19 
AnswerRe: EM algorithm Pin
El Corazon20-Nov-07 7:35
El Corazon20-Nov-07 7:35 
QuestionHow is BitBlt implemented [modified] Pin
Force Code15-Nov-07 8:15
Force Code15-Nov-07 8:15 
AnswerRe: How is BitBlt implemented Pin
Luc Pattyn15-Nov-07 8:27
sitebuilderLuc Pattyn15-Nov-07 8:27 
GeneralRe: How is BitBlt implemented Pin
Force Code15-Nov-07 8:43
Force Code15-Nov-07 8:43 
GeneralRe: How is BitBlt implemented Pin
Luc Pattyn15-Nov-07 9:22
sitebuilderLuc Pattyn15-Nov-07 9:22 
GeneralRe: How is BitBlt implemented Pin
Force Code15-Nov-07 9:54
Force Code15-Nov-07 9:54 
GeneralRe: How is BitBlt implemented Pin
Luc Pattyn15-Nov-07 10:16
sitebuilderLuc Pattyn15-Nov-07 10:16 
GeneralRe: How is BitBlt implemented [modified] Pin
Force Code15-Nov-07 11:12
Force Code15-Nov-07 11:12 
GeneralRe: How is BitBlt implemented Pin
Luc Pattyn15-Nov-07 12:03
sitebuilderLuc Pattyn15-Nov-07 12:03 
GeneralRe: How is BitBlt implemented [modified] Pin
Force Code15-Nov-07 13:19
Force Code15-Nov-07 13:19 
GeneralRe: How is BitBlt implemented Pin
Luc Pattyn15-Nov-07 14:01
sitebuilderLuc Pattyn15-Nov-07 14:01 
GeneralI Completely agree with DQNOK Pin
CPallini16-Nov-07 4:25
mveCPallini16-Nov-07 4:25 
GeneralRe: I Completely agree with DQNOK Pin
Luc Pattyn16-Nov-07 6:08
sitebuilderLuc Pattyn16-Nov-07 6:08 
GeneralRe: How is BitBlt implemented Pin
Dan Neely15-Nov-07 10:48
Dan Neely15-Nov-07 10:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.