Tuesday, May 6, 2008

CTP2: get-random -maximum

Just something to note, when using the -maximum flag to the new get-random cmdlet, you're actually defining a value that is considered exclusive. In other words, you might think the following will give you numbers between 1 and 10 (10 being inclusive):

get-random -minimum 1 -maximum 10

In actuality, the above gives you numbers starting at 1 to 9 inclusively:

CTP2>1..100|foreach-object{get-random -min 1 -max 10}|
>> group-object|sort-object name|
>> format-table -a name,@{label="Count";exp={"#"*$_.count}}
>>

Name Count
---- -----
1 ###################
2 #######
3 ##########
4 ###########
5 #####
6 ######
7 ##############
8 ###############
9 #############

CTP2>

The above is just a quick way to show the results visually. Each "#" represents the number of times that particular number showed up after 100 tries.