Possibly cursed #PHP for randomising a string from a set of elements:
```
echo implode(' ', array_fill(0, 5, new class {
function __toString() {
return ['has', 'anyone', 'really', 'been',
'far'][mt_rand(0, 4)];
}
}));
```
Possibly cursed #PHP for randomising a string from a set of elements:
```
echo implode(' ', array_fill(0, 5, new class {
function __toString() {
return ['has', 'anyone', 'really', 'been',
'far'][mt_rand(0, 4)];
}
}));
```
@loke That's pretty terse! Thanks for sharing :)
@annika Are the strings allowed to repeat?
I will now do what all obnoxious language designers do, and that is to show how nice and concise an algorithm is in one's own language (this is a version where repeats are not allowed):
(?⍨≢)⍛⊇ "has" "anyone" "really" "been" "far"Well, this only generates the permutation. Unfortunately, interspersing the spaces between the words is a bit ugly:
⊃,/↓,@\s,⍪ (?⍨≢)⍛⊇ "has" "anyone" "really" "been" "far"@Girgias sorry you didn't like it :(
@annika what? At this point you might as well use a custom closure with array_sort after generating a random sequence of 5 numbers?
Also can't this be done with the new Random extension?
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.