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
https://forums.phpfreaks.com/topic/24914-random-number/#findComment-113553
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
https://forums.phpfreaks.com/topic/24914-random-number/#findComment-113554
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
https://forums.phpfreaks.com/topic/24914-random-number/#findComment-113686
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.