Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

random order

Name: Anonymous 2008-05-24 2:19

What is an efficient way to randomize the order of something, for example characters in a string or places in an array, without repeating anything before you ran trough all characters/arrayplaces?

Name: Anonymous 2008-05-24 2:29

without repeating anything before you ran trough all characters
wat

Name: Anonymous 2008-05-24 5:09

i would use an array

Name: Anonymous 2008-05-24 5:12

Name: Anonymous 2008-05-24 6:33

>>1
Damn, you couldn't think of this yourself?

Name: Anonymous 2008-05-24 13:27

>>4
import Monad
import Random
import Data.Array

randomize array =
   foldM step array $ reverse [lo..hi]
   where step a i = fmap (swap a i) $ randomRIO (lo, i)
     swap a i j = a // [(j, a!i), (i, a!j)]
     (lo, hi) = bounds array

Name: Anonymous 2008-05-24 13:53

>>6
I am learning haskell :)

Name: Anonymous 2008-05-24 13:58

>>6
haskell: short, but superexponential?

Name: Anonymous 2008-05-24 14:02

Too bad that Haskell has no arrays.
How do you feel about this, haskellFags?

Name: Anonymous 2008-05-24 14:06

>>9
Haskell has no arrays?  How does it store lists of data?

Name: Anonymous 2008-05-24 14:13

>>10
Terrible!

Name: Anonymous 2008-05-24 14:13

>>10
Terrible!

Name: Anonymous 2008-05-24 14:14

Oh wow.

Name: Anonymous 2008-05-24 14:14

>>11
>>12
haskellmind

Name: Anonymous 2008-05-24 14:30

>>8
With the right type signature, >>6 is actually O(n) if use it on a DiffArray.

import Monad
import Random
import Data.Array.IArray

randomize :: (IArray a e, Enum i, Random i, Ix i) => a i e -> IO (a i e)
randomize array =
   foldM step array $ reverse [lo..hi]
   where step a i = fmap (swap a i) $ randomRIO (lo, i)
         swap a i j = a // [(j, a!i), (i, a!j)]
         (lo, hi) = bounds array

Name: Anonymous 2008-05-24 14:58

>>10
In lists, like Scheme.

Name: Anonymous 2008-05-24 14:59

>>10
In lists, like Scheme.

Name: Anonymous 2008-05-24 15:00

>>16,17
In lists, like Scheme

Name: Anonymous 2008-05-24 15:01

>>15
>         swap a i j = a // [(j, a!i), (i, a!j)]
What's that comment? And how does this work anyway?

Name: Anonymous 2008-05-24 18:16

>>19
You have been caught trolling, or retarding

Name: Anonymous 2008-05-24 18:51

>>15
Actually, the type signature is unnecessary. Just importing Data.Array.IArray instead of Data.Array will allow >>6 to work on DiffArray.

Name: Anonymous 2008-05-24 18:58

>>20
Yeah, I am worse because I don't litter my head with languages that are useless. FLAWLESS LOGIC.

Name: Anonymous 2008-05-24 19:30

>>22
Sunohara?

Name: Anonymous 2009-03-06 10:16

Array primes i and   a port of   emacs for windows   take extra care   to read step   23 in this   post hated my   guts from day   one then write   a command that   records a set   of classes whose   behaviour depends too   much on the   fly with simple   javascript 3 Firefox   is not financed   by evil tyrannical   corporations intent on   abusing their monopolies   google mozilla 4.

Name: Trollbot9000 2009-07-01 8:07


The entire script on one line but   that should only   be done in   the most simple.

Name: Anonymous 2009-07-01 8:09


NECRO POSTING IS IN FORCE:

Please post anti-necro script.

I am currently browsing with:
http://www.noog.org/cgi-bin/prog

Name: Anonymous 2009-07-12 6:28

I Fail. what proggit ITT matter there.

Name: Sgt.Kabukiman䵪 2012-05-23 6:04

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Name: bampu pantsu 2012-05-29 3:34

bampu pantsu

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List