FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Filling an array with random input doesn't quite work
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: solved! Re: Filling an array with random input doesn't quite work [message #185220 is a reply to message #185217] Thu, 13 March 2014 01:14 Go to previous messageGo to previous message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma:
Senior Member
On Wed, 12 Mar 2014 22:49:38 +0000, Tim Streater wrote:

> In article <85dkidwa0h67(dot)ecj3ezgrqtzk$(dot)dlg(at)40tude(dot)net>, richard
> <noreply(at)example(dot)com> wrote:
>
> You're welcome.
>
>> $x=1;
>> while ($x<40){
>> $yr=rand(1,10);
>> $yr=$yr+59;
>>
>> $num=rand(1,100);
>> if ($num<100){$num="0".$num;}
>> if ($num<10){$num="0".$num;}
>
> What is the point if this second "if"? You've already covered that with
> the first.
>

I do it this way because I've been doing the same method in BASIC for
years. It works fine.
It also helps for sorting purposes.
by having all the strings the same length helps to guarantee that sorting
will not screw it up.

When the number equals 1,
the first "if" adds a zero.
The second "if" adds another zero because it is less than 10.
numbers between 10 and 100 only get one zero added.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: readdir lists randomly
Next Topic: Nested PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 06:16:17 GMT 2024

Total time taken to generate the page: 0.05303 seconds