Jump to content

random number


bob_rock

Recommended Posts

Something like;

[code]<?php

$iRandMin = 0;
$iRandMax = 9;
$iNumOfRandomInts = 5;
$aNumbers = array();

for($i = 0; $i < $iNumOfRandomInts;)
{
$iRand = rand($iRandMin, $iRandMax);
if(in_array($iRand, $aNumbers))
{
continue;
}else{
$aNumbers[] = $iRand;
$i++;
}
}
print_r($aNumbers); //** array with your random numbers in it.
?>[/code]

I dunno if there are any php funcs to do this, so yeah...

Tip: If your going to use this, turn it into a function :)
Note: Mathematically, this could take forever, if the values that come up are already in the array...

hth.
Link to comment
Share on other sites

Here it is, don't know if this is ok , but it's almost working.
It reads the number of letters in the word and then it randomly prints out the letters.
The anoying thing is that the letters repeat...
Sorry for my bad english ...  :P
<?php
$beseda='Nina';
$sum=strlen($beseda);
$i=1;
$c=$sum-1;
do {
$a=$sum-($sum-$i);
$i++;
$b=rand(0,"$c");
$crka=$beseda[$b];
echo $crka;
} while($a<$sum);
?>
Link to comment
Share on other sites

[quote author=alpine link=topic=112513.msg456753#msg456753 date=1161691682]
If i understand your last post correctly you want to randomize the string "Nina" ?
[code]
<?php

$beseda = 'Nina';
$pieces = str_split($beseda);
shuffle($pieces);
foreach($pieces as $piece)
{
echo $piece;
}

?>
[/code]
[/quote]

There is also [code=php:0]str_shuffle('Nina');[/code] Though you need a version of at least 4.3 in PHP
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.