Activity Stream
48,167 MEMBERS
64330 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32
  1.     
    #11
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Clocked 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
    This gives results where the lower number is more likley.

    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


  2.   Sponsored Links

  3.     
    #12
    Respected 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 && ($min $step) < $max)
        {
            
    $step = ($step $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]);

    This actually needs a class but I'm sure that's no problem for you . (didn't test it btw)

  4.     
    #13
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Don'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 && ($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)); 
    This would work to get less than 70 most of the time 70%.
    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


  5.     
    #14
    Respected 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 && ($min $step) < $max)
        {
            
    $step = ($step $max $min) ? $max $min $step 3;
        }
    }

    function 
    GetNext()
    {
        global 
    $matrix$index;
        return (
    $index count($matrix)) ? rand(1$matrix[$index++]) : rand(1$matrix[$index]);
    }

    ?>
    PS: PHP is shyte.

    Edit:
    Your other way doesn't do what he wants it to do.

  6.     
    #15
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    yea 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. 
    But i still think my other one is good aswell.
    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


  7.     
    #16
    Respected 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.

  8.     
    #17
    ლ(ಠ益ಠლ)
    Website's:
    extremecoderz.com
    i win. face it

  9.     
    #18
    Respected Developer
    Website's:
    wrzc.org
    Quote Originally Posted by Hyperz View Post
    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.
    lol 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

  10.     
    #19
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Well 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  );; 
    Hope this helps dood, its a sexy and small way

    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


  11.     
    #20
    Respected Developer
    Quote Originally Posted by Mr Happy View Post
    lol 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.
    Maybe you should explain again what you want it to do. I thought you wanted to generate a random numbers that with each generated number have a higher probability of generating a bigger value. Since your friend suggested a matrix with a curve etc.

Page 2 of 4 FirstFirst 1234 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with number of posts at homepage
    By bdr111446 in forum Wordpress
    Replies: 0
    Last Post: 21st May 2012, 03:10 PM
  2. Problem on DLE 9.3 Error Number: 1267
    By Devils in forum Technical Help Desk Support
    Replies: 6
    Last Post: 26th Sep 2011, 04:17 PM
  3. From random to more random
    By dannym23 in forum General Discussion
    Replies: 4
    Last Post: 13th Aug 2011, 07:35 PM
  4. DLE random log out problem
    By seraphim in forum Webmaster Discussion
    Replies: 0
    Last Post: 12th May 2011, 01:36 PM
  5. How to get those random ads?
    By DXS in forum Webmasters, Money Making
    Replies: 3
    Last Post: 8th Mar 2009, 08:13 AM

Tags for this Thread

BE SOCIAL