PHP intval()
-
No, they're using a Discourse post. Excel would be an improvement.
-
Ah, the glory of broken parsingI hope it really comes out as preview claims it will.
Edit: It did! Yay!
-
User | Flag count | Badge progress|
@Arantor | 7 | 1% |
Why not just do it in Markdown? All it did was close your hr tags.
-
is this a barrier to reading?
-
-
Yes it is. We need a badge for that.
That reminds me. From the second of these evil scripts I'm looking at, I found this particular gem, directly from the source:
$file_size=intval("0000013920");
There's a WTF, since I have no idea yet what that's about.
I'm also trying to work out WTF this is all about:
if(round(0+1572+1572+1572)<mt_rand(round(0+796),round(0+3915))) array_keys($_16,$_17,$this,$_12);
But I haven't unpicked the rest of it yet, so anything's possible.
-
There's a character limit, but you can create large content with few characters.
for(var i = 0; i < 10000; i++) { document.write('<hr>'); }
-
```
$file_size=intval("0000013920");Yay for quoting code properly. I'll just leave it like that cos I can't be arsed to fix it while drunk. Anyway, to the point I was going to make: that's a particularly unusual octal number...
-
intval just converts it to 13920 decimal.
-
You are at where I hope to be in an hour.
-
Let's simplify that:
if(round(0+1572+1572+1572)<mt_rand(round(0+796),round(0+3915))) array_keys($_16,$_17,$this,$_12);
if (4716 < rand(796, 3915))
And we can stop there. There is no number in
[796, 3915)
that is greater than 4716.That line does nothing and is there to confuse you.
-
Oh, I'd guessed that's the general vibe, there's a lot of lines in the script that do nothing, this is merely one of them.
-
Not being a PHP guy, what if anything is the difference between rand() and mt_rand()?
-
rand() is the original random function, mt_rand() is an implementation of the Mersenne Twister which is substantially better than the original rand() function in terms of randomness.
-
mysql_real_rand()
Looks cleaner than my code:
print qq(<p class=bold align=center>You are accessing this page from IP address $ENV{'REMOTE_ADDR'}<br> all edits are logged</p><hr size=1 noshade>);
-
I can't believe they didn't name it super_rand()
-
Well, they couldn't rewrite the behaviour of rand() itself because things might be out that which depend on it, and the new random function is based on the Mersenne Twister so mt_rand is one of the less insane names for it.
real_rand() possibly might have worked but on the flip side it might have implied something about randomness that wasn't accurate (if, say, it were to access /dev/random or /dev/urandom or something)
Liking @chubertdev's code there. Broken. Not sure if Discourse. <insert Fry picture looking confused>
Filed under: because PHP is the only environment to have weird naming rules
-
they couldn't rewrite the behaviour of rand() itself because things might be out that which depend on it,
While I'm aware of Monte Carlo methods, that's still a poor idea on several levels. (Depending on a system RNG to produce reproducible behaviour is bad. Doing simulation work in PHP… clbuttic.)
-
I'm not actually sure WTF the old PHP rand() was based on. I just know it was crap and is generally considered deprecated in favour of using mt_rand(). Hilariously, when first implemented, you had to manually seed it. It didn't get seeded with process id or system timestamp or anything and so was totally repeatable from the off, which is less useful than you might think.
You wouldn't generally do simulation work in PHP unless you didn't really have any other choice and fortunately there's almost always other choice, even down to reusing the data random.org makes available in chunks of random numbers.
-
Why not just do it in Markdown? All it did was close your hr tags.
Because it's broken. Try doing it using 3 backticks for code blocks.
--- turns back into dashes as soon as you close the code block,
<hr>
adds an extra newline between it and code block. and<code>
isn't 100% width, which is what I wanted.
-
Not being a PHP guy, what if anything is the difference between rand() and mt_rand()?
Beyond the algorithm as already stated, when introduced it was 4 times faster (the difference here is less pronounced these days apparently), and the period of the two is different (232 vs 219937 − 1)
-
no repro
-
Thanks to you and PJH. Always happy to be educated.
-
If we can save one soul from TRWTF that is PHP, we have succeeded.
-
-
Liking @chubertdev's code there. Broken. Not sure if Discourse. <insert Fry picture looking confused>
Nope, that's valid Perl.
-
Ye gods.
-
And it's much cleaner than most of the code that I've been dealing with.
-
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = $year + 1900; $year_dropdown .= qq(<option value="$count" $select_year{$count}>$count</option>); $year = $year + 1; $year_dropdown .= qq(<option value="$count" $select_year{$count}>$count</option>); $year = $year + 1; $year_dropdown .= qq(<option value="$count" $select_year{$count}>$count</option>); $year = $year + 1; $year_dropdown .= qq(<option value="$count" $select_year{$count}>$count</option>);
-
If I haven't either made it public, or made a public copy by Monday, someone remind me by PM...
Since I've been reminded...
-
Umm — let's see,
$year
isn't used usefully anywhere in this snippet, so assuming:)$count
s/b$year
, we have:my ( $year_dropdown, $year ) = ( q[], localtime( time )[ 5 ] + 1900 ); $year_dropdown .= qq[<option value="$_" >$_</option>] for $year..($year+$magic_offset_number);
Golfed that for you!
-
Whoops, the
$count
variable is from the new version in a loop.