Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • random_int and random_bytes functions PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 110
    Comment on it

    Welcome to Findnerd.
    There are two new functions named random_int and random_bytes which are introduced in PHP7. You can generate the cryptographically secure integers and strings with these functions. random_int takes two parameters, one is min value and other is maxvalue to be return. It will return the value from assigned range. Please have a look.

    <?php 
    echo random_int(-22,-4);
    echo random_int(344,1233);
    ?>
    

    It will result any value from -22 to -4 and other will return from 344 to 1233.

    random_bytes function will take only one argument that is the length of the bytes to return. Please have a look.

    <?php
    $bytes = random_bytes(4);
    var_dump(bin2hex($bytes));
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: