| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-m0 |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
ksmps = 32 |
| 7 |
seed 0 |
| 8 |
|
| 9 |
opcode RndInt, i, ii |
| 10 |
iStart, iEnd xin |
| 11 |
iRnd random iStart, iEnd+.999 |
| 12 |
iRndInt = int(iRnd) |
| 13 |
xout iRndInt |
| 14 |
endop |
| 15 |
|
| 16 |
opcode ArrShuffle, i[], i[] |
| 17 |
iInArr[] xin |
| 18 |
iLen = lenarray(iInArr) |
| 19 |
iOutArr[] init iLen |
| 20 |
iIndx = 0 |
| 21 |
iEnd = iLen-1 |
| 22 |
while iIndx < iLen do |
| 23 |
;get one random element and put it in iOutArr |
| 24 |
iRndIndx RndInt 0, iEnd |
| 25 |
iOutArr[iIndx] = iInArr[iRndIndx] |
| 26 |
;shift the elements after this one to the left |
| 27 |
while iRndIndx < iEnd do |
| 28 |
iInArr[iRndIndx] = iInArr[iRndIndx+1] |
| 29 |
iRndIndx += 1 |
| 30 |
od |
| 31 |
;reset end and increase counter |
| 32 |
iIndx += 1 |
| 33 |
iEnd -= 1 |
| 34 |
od |
| 35 |
xout iOutArr |
| 36 |
endop |
| 37 |
|
| 38 |
instr Test |
| 39 |
iValues[] fillarray 1, 2, 3, 4, 5, 6, 7 |
| 40 |
indx = 0 |
| 41 |
while indx < 5 do |
| 42 |
iOut[] ArrShuffle iValues |
| 43 |
printarray(iOut,"%d") |
| 44 |
indx += 1 |
| 45 |
od |
| 46 |
endin |
| 47 |
|
| 48 |
</CsInstruments> |
| 49 |
<CsScore> |
| 50 |
i "Test" 0 0 |
| 51 |
</CsScore> |
| 52 |
</CsoundSynthesizer> |
| 53 |
;example by joachim heintz |