Csound Csound-dev Csound-tekno Search About

[Csnd] Non-repeating random numbers

Date2020-09-01 22:49
FromMarcelo Carneiro de Lima
Subject[Csnd] Non-repeating random numbers
Hi. 
I am trying here to figure out how to generate non-repetitive random numbers: in kRandom random 1,8 I want to generate 8 int(kRandom) different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't. 
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

--
Marcelo Carneiro
(21) 9382-3621
(21) 3497-0193
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-01 23:01
FromPeter Burgess
SubjectRe: [Csnd] Non-repeating random numbers
If you know in advance the list of numbers you wants in a random order,  maybe you could stick them in an ftable and shuffle it? Not at my pc now to check how to do that in Csound mind.

I appreciate this might not be appropriate for your problem, it's just the best idea I could think of going from your example.

Pete

On Tue, 1 Sep 2020, 22:49 Marcelo Carneiro de Lima, <marcelo.arcos2@gmail.com> wrote:
Hi. 
I am trying here to figure out how to generate non-repetitive random numbers: in kRandom random 1,8 I want to generate 8 int(kRandom) different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't. 
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

--
Marcelo Carneiro
(21) 9382-3621
(21) 3497-0193
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-01 23:19
FromdocB <000005d2745f1ec0-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Non-repeating random numbers

may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1   
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
Hi. 
I am trying here to figure out how to generate non-repetitive random numbers: in kRandom random 1,8 I want to generate 8 int(kRandom) different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't. 
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

--
Marcelo Carneiro
(21) 9382-3621
(21) 3497-0193
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-01 23:43
FromMarcelo Carneiro de Lima
SubjectRe: [Csnd] Non-repeating random numbers
Hi, that's it, thank you. I am trying to figure out what is going on now. First I was using until instead of when opcode and trying with if statements. Why wouldn't it work?
Thank you very much again
Bests and be safe 
Marcelo 

Em ter., 1 de set. de 2020 às 19:19, docB <000005d2745f1ec0-dmarc-request@listserv.heanet.ie> escreveu:

may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1   
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
Hi. 
I am trying here to figure out how to generate non-repetitive random numbers: in kRandom random 1,8 I want to generate 8 int(kRandom) different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't. 
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

--
Marcelo Carneiro
(21) 9382-3621
(21) 3497-0193
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


--
Marcelo Carneiro
(21) 9382-3621
(21) 3497-0193
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-01 23:46
FromGuillermo Senna
SubjectRe: [Csnd] Non-repeating random numbers

You beat me to it, docB! But what happens if during the first iteration random picks the number 8. Wouldn't you have "itmp = iarr[8]" then? This is the one I was working on (but have not thoroughly tested!):

seed 0 iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8 iIndex = lenarray(iRandomNumbers) - 1 while iIndex > 0 do iIndexOne = iIndex + 1 iRnd random 0, iIndexOne iRnd = int(iRnd) % iIndexOne iTmp = iRandomNumbers[iIndex] iRandomNumbers[iIndex] = iRandomNumbers[iRnd] iRandomNumbers[iRnd] = iTmp iIndex -= 1 od printarray iRandomNumbers, "%d"

On 1/9/20 19:19, docB wrote:
may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
Hi.
I am trying here to figure out how to generate non-repetitive random numbers: in /kRandom random 1,8/ I want to generate 8 /int(kRandom)/ different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't.
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

-- 
*Marcelo Carneiro*
(21) 9382-3621
(21) 3497-0193
Skype: Carneiro3729
http://marceloarcos2.wixsite.com/marcelocarneiro
Csound mailing list Csound@listserv.heanet.ie <mailto:Csound@listserv.heanet.ie> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


Date2020-09-01 23:51
FromGuillermo Senna
SubjectRe: [Csnd] Non-repeating random numbers
Sorry, my email client mangled the code. Here it goes again:

iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8


iIndex = lenarray(iRandomNumbers) - 1

while iIndex > 0 do

iIndexOne = iIndex + 1

iRnd random 0, iIndexOne

iRnd = int(iRnd) % iIndexOne

iTmp = iRandomNumbers[iIndex]

iRandomNumbers[iIndex] = iRandomNumbers[iRnd]

iRandomNumbers[iRnd] = iTmp

iIndex -= 1

od


printarray iRandomNumbers, "%d"


El mar., 1 sept. 2020 a las 19:46, Guillermo Senna (<gsenna@gmail.com>) escribió:

You beat me to it, docB! But what happens if during the first iteration random picks the number 8. Wouldn't you have "itmp = iarr[8]" then? This is the one I was working on (but have not thoroughly tested!):

seed 0 iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8 iIndex = lenarray(iRandomNumbers) - 1 while iIndex > 0 do iIndexOne = iIndex + 1 iRnd random 0, iIndexOne iRnd = int(iRnd) % iIndexOne iTmp = iRandomNumbers[iIndex] iRandomNumbers[iIndex] = iRandomNumbers[iRnd] iRandomNumbers[iRnd] = iTmp iIndex -= 1 od printarray iRandomNumbers, "%d"

On 1/9/20 19:19, docB wrote:
may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
Hi.
I am trying here to figure out how to generate non-repetitive random numbers: in /kRandom random 1,8/ I want to generate 8 /int(kRandom)/ different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't.
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

-- 
*Marcelo Carneiro*
(21) 9382-3621
(21) 3497-0193
Skype: Carneiro3729
http://marceloarcos2.wixsite.com/marcelocarneiro
Csound mailing list Csound@listserv.heanet.ie <mailto:Csound@listserv.heanet.ie> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-02 00:19
FromMarcelo Carneiro de Lima
SubjectRe: [Csnd] Non-repeating random numbers
It also worked fine here, thank you. Can you explain it to me?
Thank you very much
Best and be safe
Marcelo

Em ter., 1 de set. de 2020 às 19:52, Guillermo Senna <gsenna@gmail.com> escreveu:
Sorry, my email client mangled the code. Here it goes again:

iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8


iIndex = lenarray(iRandomNumbers) - 1

while iIndex > 0 do

iIndexOne = iIndex + 1

iRnd random 0, iIndexOne

iRnd = int(iRnd) % iIndexOne

iTmp = iRandomNumbers[iIndex]

iRandomNumbers[iIndex] = iRandomNumbers[iRnd]

iRandomNumbers[iRnd] = iTmp

iIndex -= 1

od


printarray iRandomNumbers, "%d"


El mar., 1 sept. 2020 a las 19:46, Guillermo Senna (<gsenna@gmail.com>) escribió:

You beat me to it, docB! But what happens if during the first iteration random picks the number 8. Wouldn't you have "itmp = iarr[8]" then? This is the one I was working on (but have not thoroughly tested!):

seed 0 iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8 iIndex = lenarray(iRandomNumbers) - 1 while iIndex > 0 do iIndexOne = iIndex + 1 iRnd random 0, iIndexOne iRnd = int(iRnd) % iIndexOne iTmp = iRandomNumbers[iIndex] iRandomNumbers[iIndex] = iRandomNumbers[iRnd] iRandomNumbers[iRnd] = iTmp iIndex -= 1 od printarray iRandomNumbers, "%d"

On 1/9/20 19:19, docB wrote:
may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
Hi.
I am trying here to figure out how to generate non-repetitive random numbers: in /kRandom random 1,8/ I want to generate 8 /int(kRandom)/ different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't.
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

-- 
*Marcelo Carneiro*
(21) 9382-3621
(21) 3497-0193
Skype: Carneiro3729
http://marceloarcos2.wixsite.com/marcelocarneiro
Csound mailing list Csound@listserv.heanet.ie <mailto:Csound@listserv.heanet.ie> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


--
Marcelo Carneiro
(21) 9382-3621
(21) 3497-0193
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-02 00:26
FromGuillermo Senna
SubjectRe: [Csnd] Non-repeating random numbers

Yes, it's supposed to be an implementation of the Fisher-Yates shuffling algorithm. Here's a video: https://www.youtube.com/watch?v=tLxBwSL3lPQ

On 1/9/20 20:19, Marcelo Carneiro de Lima wrote:
It also worked fine here, thank you. Can you explain it to me?
Thank you very much
Best and be safe
Marcelo

Em ter., 1 de set. de 2020 às 19:52, Guillermo Senna <gsenna@gmail.com>
escreveu:

Sorry, my email client mangled the code. Here it goes again:

iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8


iIndex = lenarray(iRandomNumbers) - 1

while iIndex > 0 do

iIndexOne = iIndex + 1

iRnd random 0, iIndexOne

iRnd = int(iRnd) % iIndexOne

iTmp = iRandomNumbers[iIndex]

iRandomNumbers[iIndex] = iRandomNumbers[iRnd]

iRandomNumbers[iRnd] = iTmp

iIndex -= 1

od


printarray iRandomNumbers, "%d"

El mar., 1 sept. 2020 a las 19:46, Guillermo Senna (<gsenna@gmail.com>)
escribió:

You beat me to it, docB! But what happens if during the first iteration
random picks the number 8. Wouldn't you have "itmp = iarr[8]" then? This is
the one I was working on (but have not thoroughly tested!):

seed 0 iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8 iIndex =
lenarray(iRandomNumbers) - 1 while iIndex > 0 do iIndexOne = iIndex + 1
iRnd random 0, iIndexOne iRnd = int(iRnd) % iIndexOne iTmp =
iRandomNumbers[iIndex] iRandomNumbers[iIndex] = iRandomNumbers[iRnd]
iRandomNumbers[iRnd] = iTmp iIndex -= 1 od printarray iRandomNumbers, "%d"

On 1/9/20 19:19, docB wrote:

may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:

Hi.
I am trying here to figure out how to generate non-repetitive random
numbers: in /kRandom random 1,8/ I want to generate 8 /int(kRandom)/
different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be
a good result, but 2,2,3,4,5,6,8,7 couldn't.
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

--
*Marcelo Carneiro*
(21) 9382-3621
(21) 3497-0193
Skype: Carneiro3729
http://marceloarcos2.wixsite.com/marcelocarneiro
Csound mailing list Csound@listserv.heanet.ie
<mailto:Csound@listserv.heanet.ie> <Csound@listserv.heanet.ie>
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
https://github.com/csound/csound/issues Discussions of bugs and features
can be posted here


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
https://github.com/csound/csound/issues Discussions of bugs and features
can be posted here



Date2020-09-02 00:47
FromdocB <000005d2745f1ec0-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Non-repeating random numbers

this is a good question:

how likely is it that int(random(0,8))==8 -- i couldnt so far figure out from the code if it can happen at all

this may be worth a hint in the docs

nevertheless, in your code the % operation ensures the < 8 condition.

best christian

On 9/2/20 12:46 AM, Guillermo Senna wrote:

You beat me to it, docB! But what happens if during the first iteration random picks the number 8. Wouldn't you have "itmp = iarr[8]" then? This is the one I was working on (but have not thoroughly tested!):

seed 0 iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8 iIndex = lenarray(iRandomNumbers) - 1 while iIndex > 0 do iIndexOne = iIndex + 1 iRnd random 0, iIndexOne iRnd = int(iRnd) % iIndexOne iTmp = iRandomNumbers[iIndex] iRandomNumbers[iIndex] = iRandomNumbers[iRnd] iRandomNumbers[iRnd] = iTmp iIndex -= 1 od printarray iRandomNumbers, "%d"

On 1/9/20 19:19, docB wrote:
may be something like this could work:

from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
; ==============================================
<CsInstruments>

sr    =    48000
ksmps    =    1
;nchnls    =    2
0dbfs    =    1

instr 1
  iarr[] fillarray 0,1,2,3,4,5,6,7
  icount = 8;
  while  icount > 1 do
    idx random 0, icount
    itmp = iarr[idx]
    iarr[idx] = iarr[icount-1]
    iarr[icount-1] = itmp
    icount = icount - 1
  od
  printarray iarr
endin

</CsInstruments>
; ==============================================
<CsScore>
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0
i1 0 0


</CsScore>
</CsoundSynthesizer>

On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
Hi.
I am trying here to figure out how to generate non-repetitive random numbers: in /kRandom random 1,8/ I want to generate 8 /int(kRandom)/ different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 could be a good result, but 2,2,3,4,5,6,8,7 couldn't.
Any help would be appreciated.
Thank you and be safe.
best
Marcelo

-- 
*Marcelo Carneiro*
(21) 9382-3621
(21) 3497-0193
Skype: Carneiro3729
http://marceloarcos2.wixsite.com/marcelocarneiro
Csound mailing list Csound@listserv.heanet.ie <mailto:Csound@listserv.heanet.ie> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-09-02 22:30
Fromjoachim heintz
SubjectRe: [Csnd] Non-repeating random numbers
i wrote a udo here:
https://github.com/csudo/csudo/blob/master/arrays/ArrPermRnd.csd

this is some time ago, so the code could be more condensed.  but it 
seems to work:
  iArr[] genarray 1, 10
  iArr[] ArrPermRnd iArr
  printarray iArr

->  9.0000 3.0000 10.0000 1.0000 2.0000 6.0000 7.0000 8.0000 5.0000 4.0000

best -
	joachim



On 02/09/2020 01:47, docB wrote:
> this is a good question:
> 
> how likely is it that int(random(0,8))==8 -- i couldnt so far figure out 
> from the code if it can happen at all
> 
> this may be worth a hint in the docs
> 
> nevertheless, in your code the % operation ensures the < 8 condition.
> 
> best christian
> 
> On 9/2/20 12:46 AM, Guillermo Senna wrote:
>>
>> You beat me to it, docB! But what happens if during the first 
>> iteration random picks the number 8. Wouldn't you have "itmp = 
>> iarr[8]" then? This is the one I was working on (but have not 
>> thoroughly tested!):
>>
>> seed 0 iRandomNumbers[] fillarray 1, 2, 3, 4, 5, 6, 7, 8 iIndex = 
>> lenarray(iRandomNumbers) - 1 while iIndex > 0 do iIndexOne = iIndex + 
>> 1 iRnd random 0, iIndexOne iRnd = int(iRnd) % iIndexOne iTmp = 
>> iRandomNumbers[iIndex] iRandomNumbers[iIndex] = iRandomNumbers[iRnd] 
>> iRandomNumbers[iRnd] = iTmp iIndex -= 1 od printarray iRandomNumbers, 
>> "%d"
>>
>> On 1/9/20 19:19, docB wrote:
>>> may be something like this could work:
>>>
>>> from: https://maths-people.anu.edu.au/~brent/pd/Arndt-thesis.pdf
>>>
>>> 
>>> 
>>> 
>>> ; ==============================================
>>> 
>>>
>>> sr    =    48000
>>> ksmps    =    1
>>> ;nchnls    =    2
>>> 0dbfs    =    1
>>>
>>> instr 1
>>>   iarr[] fillarray 0,1,2,3,4,5,6,7
>>>   icount = 8;
>>>   while  icount > 1 do
>>>     idx random 0, icount
>>>     itmp = iarr[idx]
>>>     iarr[idx] = iarr[icount-1]
>>>     iarr[icount-1] = itmp
>>>     icount = icount - 1
>>>   od
>>>   printarray iarr
>>> endin
>>>
>>> 
>>> ; ==============================================
>>> 
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>> i1 0 0
>>>
>>>
>>> 
>>> 
>>>
>>> On 9/1/20 11:49 PM, Marcelo Carneiro de Lima wrote:
>>>> Hi.
>>>> I am trying here to figure out how to generate non-repetitive random 
>>>> numbers: in /kRandom random 1,8/ I want to generate 8 /int(kRandom)/ 
>>>> different numbers at once without repetitions. So 2,3,4,5,1,7,8,6 
>>>> could be a good result, but 2,2,3,4,5,6,8,7 couldn't.
>>>> Any help would be appreciated.
>>>> Thank you and be safe.
>>>> best
>>>> Marcelo
>>>>
>>>> -- 
>>>> *Marcelo Carneiro*
>>>> (21) 9382-3621
>>>> (21) 3497-0193
>>>> Skype: Carneiro3729
>>>> http://marceloarcos2.wixsite.com/marcelocarneiro
>>>> Csound mailing list Csound@listserv.heanet.ie 
>>>>  
>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to 
>>>> https://github.com/csound/csound/issues Discussions of bugs and 
>>>> features can be posted here 
>>>
>>> Csound mailing list
>>> Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>> Send bugs reports to
>>> https://github.com/csound/csound/issues
>>> Discussions of bugs and features can be posted here
>>>
>> Csound mailing list Csound@listserv.heanet.ie 
>>  
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to 
>> https://github.com/csound/csound/issues Discussions of bugs and 
>> features can be posted here 
> Csound mailing list Csound@listserv.heanet.ie 
>  
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to 
> https://github.com/csound/csound/issues Discussions of bugs and features 
> can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here