List Info

Thread: Re: "ocaml_beginners"::[] Shuffle To Randomize




Re: "ocaml_beginners"::[] Shuffle To Randomize
country flaguser name
Taiwan
2007-08-23 22:35:39


Surprised by William's instant reply, many thanks.

By the way, is there any browser enable
to run OCaml script to produce dynamic HTML
just like javascript effect ?

William Neumann < wneumann%40cs.unm.edu">wneumanncs.unm.edu> »¡¡G On Aug 23, 2007, at 7:49 PM, LORENZO wrote:

> So here comes my question:
> can we do the in place swap to implement
> a fisherYates() shuffle with OCaml ?

Sure. With arrays it's no problem (the randomness here isn't the
greatest, but that's another issue):

let fy_arr a =
let rec fy a = function
| 0 -> a
| i -> let swap_pos = Random.int i in
let temp = a.(i) in
a.(i) <- a.(swap_pos);
a.(swap_pos) <- temp;
fy a (pred i)
in fy a (Array.length a - 1)
;;

If you want to use lists, then no. You wouldn't be able to do in-
place modifications there.

William D. Neumann

"I eat T-bone steaks, I lift barbell plates, I'm sweeter than a
German chocolate cake. I'm the reflection of perfection, the number
one selection. I'm the man of the hour, the man with the power, too
sweet to be sour. The ladies' pet, the men's regret, where what you
see is what you get, and what you don't see, is better yet."

--Superstar Billy Graham



Messages in this topic (0) Reply (via web post) | Start a new topic
Messages | Database | Members | Calendar
Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid flames etc.

Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch format to Traditional
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

Recent Activity

2
New Members

Visit Your Group
Yahoo! Finance
It's Now Personal
Guides, news,
advice & more.

New web site?
Drive traffic now.
Get your business
on Yahoo! search.

Best of Y! Groups
Check out the best
of what Yahoo!
Groups has to offer.



.


__,_._,__
_________________________________________________
´I°Ó¤½¶}¼x±B¡AÄa½à30¸U¤¸½Ð§AÀ°¥L°µ¨M©w¡C

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Shuffle To Randomize
country flaguser name
United Kingdom
2007-08-24 05:31:25

On Fri, Aug 24, 2007 at 11:35:39AM +0800, arniwarp wrote:
&gt;
> Surprised by William's instant reply, many thanks.
>
> By the way, is there any browser enable
&gt; to run OCaml script to produce dynamic HTML

Wasn't this a feature of the MMM browser?
http://pauillac.inria.fr/~rouaix/mmm/

Anyway, executing untrusted OCaml code isn't safe unless you do two
things: (1) Disable large parts of the language, and (2) Don't execute
bytecode directly, but compile each time.

(1) and (2) are something which Xavierbot tries to do, hopefully
successfully. http://et.redhat.com/~rjones/xavierbot/

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )