Simulating the randIntNoRep( command on the TI 83
質問
The randIntNoRep(
command has been released for the TI-84+/SE calculator on OS 2.53MP and above.
The command is used when you need to create a list of numbers in random order in which no integer is repeated. It is very useful for shuffling a sequence of any numbers. How can I implement this functionality on an earlier version (OS or device-wise)?
解決
This can be achieved by creating a list of random numbers, and using it to sequence a second list of the numbers that you want randomized.
For example, randomizing a 52 card deck and saving it as a list can be done easily with randIntNoRep(
:
:randIntNoRep(0,51→L₁
This can be simulated using the following code:
:rand(52→L₂
:seq(X,X,0,51→L₁
:SortA(L₂,L₁
L₂
is set to contain a set of 52 random values. L₁
is set to contain the numbers that will be randomized. By sequencing the lists in ascending order, the same method can be achieved as using randIntNoRep(
.
他のヒント
You can randomize a list by swapping its elements, like this.
:For(F,1,dim(L1))
: iPart(dim(L1)rand+1)->R
: L1(R)->T
: L1(F)->L1(R)
: T->L1(F)
:End
This randomize L1, assuming L1 has all the elements you want it to.