![]() ![]() (Note that seeding the RNG with the same seed and the SHA1PRNG algorithm produces a different "starting point" for random numbers for each seeding.) If you refresh this page, set W will changes sets X, Y, and Z will not. Sets A, B, and C are all different.Ĭall RandRange(1, 100, "SHA1PRNG") 10 times If you refresh this page, set A will change sets B and C will not. (all this was tested in CF 8.0.1, Standard Edition)Ĭalling Randomize with the same seed and the default algorithm will generate the same sequence with RandRange for every call the sets of random numbers will all be the same.Ĭalling Randomize with the same seed and the SHA1PRNG algorithm will generate the same set of sequences with RandRange the sets will be different but the contents of each set will be the same. Yes, Randomize() affects RandRange() as well as Rand(). I know this is old, and you've probably figured this out by now, but for completion's sake (and because I was searching for reasons to use Randomize or not). ![]() Obviously the array was completely filled with strings before too, but why no error? Any ideas? Java Collections Shuffle() Įither I'm retarded or I must have not had enough coffee this morning (I'd prefer to think the latter).įor some reason sorting the array as 'numeric' works for having the ordered pairs w/ randRange 10 and (sometimes) it tosses an error on random elements (go figure) saying it was string. So, I guess the lesson learned here is that RandRange() is selecting numbers randomly and I am just paranoid :)ĭeep thoughts by - ColdFusion RandRange() vs. But, when I changed from 1000 iterations down to 10 iterations, I found exactly the same average and random number distribution. I thought maybe that large set is just easy to even out on. To make sure the counts were evenly distributed, I created an Arra圜ount() method that takes an array and a value and returns the number of times that (simple) value can be found in the array:Īrra圜ount( 1 ): #Arra圜ount( arrRandRange, 1 )#Īrra圜ount( 2 ): #Arra圜ount( arrRandRange, 2 )#Īrra圜ount( 3 ): #Arra圜ount( arrRandRange, 3 )#Īrra圜ount( 1 ): #Arra圜ount( arrShuffle, 1 )#Īrra圜ount( 2 ): #Arra圜ount( arrShuffle, 2 )#Īrra圜ount( 3 ): #Arra圜ount( arrShuffle, 3 )#Īgain, running the above code shows a very even distribution of values:įor everything above, I was testing on 1000 iterations. Running the above code, the numbers always come out to be roughly the same:īut, what about the value distribution? 1000 2s could look the same as 500 1s and 3s. Both loops randomly select the values 1,2, or 3. Then, I am shuffling another array and selecting the first value from it to populate the Shuffle() array. As you can see, I am adding RandRange() values to one array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |