Results 11 to 20 of 32
-
2nd Jul 2010, 07:01 PM #11MemberWebsite's:
litewarez.net litewarez.com triniwarez.comClocked it bitches:
Test Case:
PHP Code:$up = $down = 0;
while(true)
{
if(abs((rand()%150)-50) < 50)
{
$up++;
}else
{
$down++;
}
if( ($up + $down) == 1000){ break;} //500 loops for the test case
}
echo $up . '/' . $down;
run it keep refreshing and it will tell you the chances of the lower over the higher number.
So what you actually want is
PHP Code:$number = abs((rand()%150)-50); // 0-100
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
2nd Jul 2010, 07:23 PM #12Respected Developer
Not the best implementation of what your friend suggest (I do suck at math) but this should work. As you generate more number the chance of getting a bigger number will increase.
PHP Code:// Setup
$min = 10;
$max = 1000;
$step = 0;
$index = 0;
$matrix = array();
// curve
for ($i = 0; $i < $max; $i++)
{
$matrix[i] = $min + $step;
if ($i & 1 && ($min + $step) < $max)
{
$step = ($step + 3 > $max - $min) $max - $min : $step + 3;
}
}
// generate the next random number
function GetNext()
{
return ($index < count($matrix)) ? rand(1, $matrix[$index++]) : rand(1, $matrix[$index]);
}
. (didn't test it btw)
-
2nd Jul 2010, 09:07 PM #13MemberWebsite's:
litewarez.net litewarez.com triniwarez.comDon't work dood, just returns 1 constantly.
PHP Code:// Setup
$min = 10;
$max = 1000;
$step = 0;
$index = 0;
$matrix = array();
// curve
for ($i = 0; $i < $max; $i++)
{
$matrix[$i] = $min + $step; //Fix i to $i
if ($i & 1 && ($min + $step) < $max)
{
$step = (($step + 3) > ($max - $min)) ? ($max - $min) : ($step + 3); //Wraped calculations
}
}
// generate the next random number
function GetNext()
{
return ($index < count($matrix)) ? rand(1, $matrix[$index++]) : rand(1, $matrix[$index]);
}
echo GetNext(); //Returns 1
Just thought of another way to do it!
PHP Code:$perecntage = 70; //70% to lower side
$direction = (rand(0,100) < $percentage / ? 'lower' : 'hither'); //The chances of 0 - 100 is 70%
$number = ($direction == 'lower' ? rand(0,$percentage) : /*higher*/ rand($percentage,100));
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
3rd Jul 2010, 12:01 AM #14Respected Developer
Don't wrap my calculations and expect to live
.
Anyway, fixed the obvious:
PHP Code:<?php
$min = 10;
$max = 1000;
$step = 0;
$index = 0;
$matrix = array();
for ($i = 0; $i < $max; $i++)
{
$matrix[$i] = $min + $step;
if ($i & 1 && ($min + $step) < $max)
{
$step = ($step + 3 > $max - $min) ? $max - $min : $step + 3;
}
}
function GetNext()
{
global $matrix, $index;
return ($index < count($matrix)) ? rand(1, $matrix[$index++]) : rand(1, $matrix[$index]);
}
?>
Edit:
Your other way doesn't do what he wants it to do.
-
3rd Jul 2010, 08:14 AM #15MemberWebsite's:
litewarez.net litewarez.com triniwarez.comyea i know, the first one does using abs.
erm for some reason yours just keeps bringing back an average of 5, 1,8,9,7,8,7,9... it never gets higher then 10 and for a max of 1K it should do.
erm
PHP Code:function getRand()
{
$check = rand(0,100);
if($check < 70) //This means that 50% of the time, the below line will execute.
{
$check = rand(0,50);
//Because the chances of the above being true are 70/100, this will execute.
//And If it does not get to here then the $check will be within 70-100.
}
}
echo getRand(); //Test.
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
3rd Jul 2010, 12:14 PM #16Respected Developer
Well obviously if you keep refreshing it'll stay at a low number since the matrix and index gets rebuild every time. Put GetNext() in a for loop with 1000 irritations and you'll see it does exactly what it's supposed to do. Also, your methods aren't doing what he wants it to do. Otherwise my 1st example could be used which is still the fastest.
-
3rd Jul 2010, 12:28 PM #17ლ(ಠ益ಠლ)Website's:
extremecoderz.com
-
3rd Jul 2010, 01:12 PM #18OPRespected DeveloperWebsite's:
wrzc.orglol that's why it wasn't working for me either. I don't understand it but when it's put in a loop it does seam to work as it's meant to. Correct me if I'm wrong as I don't understand matrix but doesn't this mean that you have to run all 1000 and pick one of the 1000 at random to then get a result?
By the way for the original purpose it's not critical that this is worked out fully but I am finding it a huge learning experience which is probably more important.
@litewarez. That % thing is nice. Not exactly what I was after but I like how you did it.Tutorial How to SEO your Warez Site a guide to help you increase your organic traffic
Huge list of Warez Sites and free Multiposter Templates
-
3rd Jul 2010, 01:28 PM #19MemberWebsite's:
litewarez.net litewarez.com triniwarez.comWell lets walk threw it:
abs() is a function used to set teh Absolute value of something, so that the number is not a negative but always a positive.
rand() with no parameters creates a number from 0 to the highest available number for that operating system.
the % is an Arithmetic Modulus operator what it does is return the remainder of A devided by B.
and the -50 you know.
heres a visual example.
PHP Code:$rand = 1045676;
$mod = ($rand % 150); //basically, how many times 150 goes into 1045676 and return the remainder.
//$mod is 26
$mod = $mod-50; // -24, but after abs() becomes 24; witch is a positive
//And all together
$number = abs( ( rand() % 150 ) -50 );;
Do i win ??Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
3rd Jul 2010, 02:00 PM #20Respected Developer
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Problem with number of posts at homepage
By bdr111446 in forum WordpressReplies: 0Last Post: 21st May 2012, 03:10 PM -
Problem on DLE 9.3 Error Number: 1267
By Devils in forum Technical Help Desk SupportReplies: 6Last Post: 26th Sep 2011, 04:17 PM -
From random to more random
By dannym23 in forum General DiscussionReplies: 4Last Post: 13th Aug 2011, 07:35 PM -
DLE random log out problem
By seraphim in forum Webmaster DiscussionReplies: 0Last Post: 12th May 2011, 01:36 PM -
How to get those random ads?
By DXS in forum Webmasters, Money MakingReplies: 3Last Post: 8th Mar 2009, 08:13 AM
themaPoster - post to forums and...
Version 5.38 released. Open older version (or...