Hi,
Is there a facility in NEURON to generate nonrepeating random numbers? I am using random syntax but I don't want to repeat the numbers which already got generated.
Kindly let me know.
Thank you.
Nonrepeating random numbers
Moderator: wwlytton

 Posts: 70
 Joined: Wed Jan 18, 2012 12:25 am
 Location: University of Pavia

 Site Admin
 Posts: 5686
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: Nonrepeating random numbers
The best answer to your question depends on what you are trying to achieve. Are you generating integers or floating point numbers? If the latter, what is your threshold for deciding that two numbers are "different"?

 Posts: 70
 Joined: Wed Jan 18, 2012 12:25 am
 Location: University of Pavia
Re: Nonrepeating random numbers
Hi Ted,
I am considering integers not floating numbers.
Can you kindly let me know how to generate?
I am considering integers not floating numbers.
Can you kindly let me know how to generate?

 Site Admin
 Posts: 5686
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: Nonrepeating random numbers
Trivial algorithm. In pseudocode
"How do I know if I have seen a particular integer before?"
You could use the Vector class's indwhere() method. That might slow down as the number of elements in the Vector grows.
Alternatively, if you know in advance how many samples you need to generate, create a "picked" Vector with that many elements and set all of them to 0. Each element should correspond to one of the integers in the range from which you are sampling. Then
Code: Select all
WHILE number of samples to pick is > 0 {
REPEAT
pick i from discrete distribution
UNTIL i is one that we have not seen before
append i to the Vector that holds all the samples we have decided to keep
reduce number of samples to pick by 1
}
You could use the Vector class's indwhere() method. That might slow down as the number of elements in the Vector grows.
Alternatively, if you know in advance how many samples you need to generate, create a "picked" Vector with that many elements and set all of them to 0. Each element should correspond to one of the integers in the range from which you are sampling. Then
Code: Select all
WHILE number of samples to pick is > 0 {
REPEAT
pick i from discrete distribution
UNTIL you get one for which the corresponding element of the "picked" vector is 0
return i
decrease number of samples to pick by 1
}