ID:260155
![]() May 27 2006, 2:14 am
|
|
This command will shuffle all items in said list in a random order.
|
No, I mean L.Cut. I want to empty L at the same time so that I can re-add the elements in random order. If I did L.Copy, I would end up with L having all its elements twice - once in the original order then another time in scrambled order after that.
I did make a typo though. L.len should be temp.len, and I just fixed that. |
Ah, I see. I didn't recognize the method at first, I usually do it as stated in the post [link].
|
The code you posted will only work properly on lists with unique values. Shuffling is much easier to accomplish via Swap().
Lummox JR |
Android Data wrote:
This command will shuffle all items in said list in a random order. It'd be utterly useless to implement this internally when anyone can write a quicky shuffle proc. proc/Shuffle(list/L) Lummox JR |
I don't agree with you that it is useless to implement this internally. Although it is easiely added in, a shuffle proc would just add even more things that can be done automaticly. Perhaps it should be low on the priority listings, but it is so simple that it would take almost no effort to add into DM, then it would just be a matter of updating the reference.
|
Something that could be a little useful to newcomers is a list that could be in the reference that shows how to program simple procs such as this. After a while the newcomer would know how to edit it, and it would take less time to write this up in the reference than add it internally.
|
Scoobert wrote:
I don't agree with you that it is useless to implement this internally. Although it is easiely added in, a shuffle proc would just add even more things that can be done automaticly. Perhaps it should be low on the priority listings, but it is so simple that it would take almost no effort to add into DM, then it would just be a matter of updating the reference. Just because something is widely useful does not mean it should be implemented as a language feature. Speedwise there'd be no point, since a user-defined proc does just as well. list.Swap() and list.Insert() were vitally needed because replicating their functions was far more difficult, yet they both have major utility. A shuffle proc would have no such advantages. Instead, a shuffle proc sounds like a good candidate for a pamphlet. Those are my own idea for microlibraries that can get bundled together. Currently no pamphlet support exists, but I believe Tom found the concept intriguing so maybe at some point there will be. Lummox JR |
Android Data wrote:
Perhaps a special library could be made with some cool functions that people found to be useful? Like http://developer.byond.com/hub/Kunark/KunarkLib ? There's a few libraries by people which have a bunch of functions they commonly use. I belive ShadowDarke has one somewhere, too. |
I am assuming list/Cut asserves assosiated values as well. If it doesn't, then trying to do so where I did won't accomplish anything.
That should shuffle the list, and it should allow you to keep the same list object too so that it is properly preserved for anything that references it.