comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Random ordering
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Random ordering [message #35528] Tue, 24 June 2003 13:55
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
David Fanning wrote:
>
> trouble writes:
>
>> Stuck again. I want to create an integer 1D array from 0 to n (n ~
>> 100) so that the numbers are in jumbled up order so that "nearby"
>> numbers, eg. ABS(difference) < 3, are "far" apart. I think there must
>> be a nice way using MOD rather than bludging it with RANDOMU. Anyone
>> got any suggestions?

Any algorithm than uses MOD rather than RANDOMU must necessarily be
non-random, so I'm assuming a completely regular result is acceptable?
By "jumbled up" do you mean a permutation of indgen(n), as opposed to a
sequence that might contain repeats?
If so, then try

jumble = (jumble_increment(n,m)*INDGEN(n)) MOD n

for m=3, which is the limit you've placed on ABS(difference).
jumble_increment(n,m) is the integer between 0 and n which is nearest to
n/m, which does NOT divide 'n'. The algorithm for jumble_increment() is
left as an excersize for the reader (I'm being lazy).
Re: Random ordering [message #35529 is a reply to message #35528] Tue, 24 June 2003 13:14 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
trouble writes:

> Stuck again. I want to create an integer 1D array from 0 to n (n ~
> 100) so that the numbers are in jumbled up order so that "nearby"
> numbers, eg. ABS(difference) < 3, are "far" apart. I think there must
> be a nice way using MOD rather than bludging it with RANDOMU. Anyone
> got any suggestions?

What is you do, anyway, for a living, Trouble?

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Random ordering
Next Topic: How to do nested objects??

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:56:14 PDT 2025

Total time taken to generate the page: 0.00553 seconds