Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #13148

Re: solved! Re: Filling an array with random input doesn't quite work

Message-ID <4014262.VKcLhA6E0C@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2014-03-14 23:23 +0100
Subject Re: solved! Re: Filling an array with random input doesn't quite work
Newsgroups comp.lang.php
References <12lin35i3xsev.abk024ld5l8l.dlg@40tude.net> <85dkidwa0h67.ecj3ezgrqtzk$.dlg@40tude.net> <120320142249386192%timstreater@greenbee.net> <5320f7ca$0$6671$9b4e6d93@newsspool2.arcor-online.net>

Show all headers | View raw


Christoph Michael Becker wrote:

> Tim Streater wrote:
>> richard <noreply@example.com> wrote:
>>>  $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.
> 
> That serves to add padding to three characters.  The last three lines
> could be replaced with the following:
> 
>   str_pad(rand(1, 100), 3, '0', STR_PAD_LEFT);

  $num = str_pad(rand(1, 100), 3, '0', STR_PAD_LEFT);

as str_pad() does not modify strings (because they are immutable).

Or simply

  $num = sprintf('%03d', rand(1, 100));
 
:)


PointedEars
-- 
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Filling an array with random input doesn't quite work richard <noreply@example.com> - 2014-03-12 13:18 -0400
  Re: Filling an array with random input doesn't quite work Tim Streater <timstreater@greenbee.net> - 2014-03-12 17:36 +0000
  Re: Filling an array with random input doesn't quite work Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-12 19:02 +0000
  Re: Filling an array with random input doesn't quite work Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-12 19:06 +0000
  Re: Filling an array with random input doesn't quite work Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-12 20:34 +0000
    Re: Filling an array with random input doesn't quite work Tim Streater <timstreater@greenbee.net> - 2014-03-12 22:51 +0000
  solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) richard <noreply@example.com> - 2014-03-12 17:08 -0400
    Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Tim Streater <timstreater@greenbee.net> - 2014-03-12 22:49 +0000
      Re: solved! Re: Filling an array with random input doesn't quite work Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-13 01:11 +0100
        Re: solved! Re: Filling an array with random input doesn't quite work richard <noreply@example.com> - 2014-03-12 22:43 -0400
        Re: solved! Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-14 23:23 +0100
          Re: solved! Re: Filling an array with random input doesn't quite work Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-14 23:58 +0100
      Re: solved! Re: Filling an array with random input doesn't quite work richard <noreply@example.com> - 2014-03-12 21:14 -0400
      Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-13 02:50 +0000
      Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-13 16:23 +0000
    Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) Doug Miller <doug_at_milmac_dot_com@example.com> - 2014-03-13 02:53 +0000
  Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-12 23:02 -0400
    Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-12 23:11 -0400
      Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-14 09:31 -0400
        Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-14 11:00 -0400
          Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-14 11:47 -0400
            Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-14 12:55 -0400
              Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-14 23:10 -0400
    Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-13 00:31 -0400
  Re: Filling an array with random input doesn't quite work Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-03-14 12:42 -0700
    Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-14 23:07 +0100
      Re: Filling an array with random input doesn't quite work Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-15 21:32 +0000
        Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-15 23:14 +0100
        Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-15 22:14 -0400
          Re: Filling an array with random input doesn't quite work Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-16 02:51 +0000
            Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-16 09:46 -0400
  Re: Filling an array with random input doesn't quite work Gabriel Dragffy <usenet@moojuice.net> - 2014-03-16 14:45 +0000
    Re: Filling an array with random input doesn't quite work Norman Peelman <npeelman@cfl.rr.com> - 2014-03-16 19:52 -0400
    Re: Filling an array with random input doesn't quite work Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-17 02:16 +0000
      Re: Filling an array with random input doesn't quite work Gabe <usenet@moojuice.net> - 2014-03-17 12:43 +0000
        Re: Filling an array with random input doesn't quite work Jerry Stuckle <jstucklex@attglobal.net> - 2014-03-17 08:52 -0400
        Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-17 14:32 +0100
          Re: Filling an array with random input doesn't quite work Gabe <usenet@moojuice.net> - 2014-03-17 13:47 +0000
            Re: Filling an array with random input doesn't quite work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-17 16:07 +0100

csiph-web