phpjs
Version:
111 lines (84 loc) • 2.79 kB
HTML
<!-- Generated by Rakefile:build -->
<strong>
<a href="http://an3m1.com/" rel="nofollow">????? ???????</a>
</strong>
on 2012-04-10 09:55:00 <br />
If I might —perhaps you should consider adding a few images. I don’t mean to disrespect what you’ve said ; its very enlightening, indeed. However, I think would respond to it more positively if they could be something tangible to your ideas
<hr />
<strong>
<a href="http://bi3.biz" rel="nofollow">Eugen</a>
</strong>
on 2011-04-21 23:23:19 <br />
one example here http://javascript.about.com/library/blsort2.htm
<hr />
<strong>
Taai
</strong>
on 2011-02-08 10:58:52 <br />
I improved this code.
<pre><code>
function array_rand(input, num_req) {
var input_len, rand, indexes = [], ticks = num_req || 1;
if (input instanceof Array === false || ticks > (input_len = input.length)) {
return null;
}
while (indexes.length != ticks) {
rand = Math.floor(Math.random() * input_len);
if (indexes.indexOf(rand) == -1) {
indexes.push(rand);
}
}
return ticks == 1 ? indexes[0] : indexes;
}
</code></pre>
Some (older) browsers doesn't support Array.indexOf function, so, here is a code (wich I also improved) for those older browsers (add this code at least before array_rand):
<pre><code>
if (!Array.indexOf) {
Array.prototype.indexOf = function(obj) {
var i = 0, l = this.length;
for (; l--; i++) if (this[i] == obj) return i;
return -1;
}
}
</code></pre>
Have fun!
<hr />
<strong>
pwoul
</strong>
on 2009-05-10 03:30:30 <br />
thanks a lot, that's working now :)
(here's the code if someone needs it)
<pre><code>
var result = "";
alea = array_rand(["a","b","c","d","e","f","g","h"], 8);
for(var i in alea)
{
var kikoo = alea[i];
result = result + tableau[kikoo];
}
</code></pre>
<hr />
<strong>
<a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a>
</strong>
on 2009-05-09 23:18:59 <br />
@pwoul, You are referencing an array/object called "tableau" instead of the one you randomized, "alea". Change it to "alea" (if that's what you want), and the number will vary... best wishes, Brett
<hr />
<strong>
pwoul
</strong>
on 2009-05-09 13:25:38 <br />
Hi, first i'd like to thank you for this very nice function.
But (there's always one :D) i have a problem using it :
<pre><code>
var result = "";
var alea = array_rand(["a","b","c","d","e","f","g","h"], 8);
for(var i in alea)
{
result = result + tableau[i];
}
</code></pre>
This code always returns the string "abcdefgh", the order of the characters isn't random :/
Thanks for your help :)
<hr />