Generating a secure random numbers using php7

Posted in: Articles by musiitwa joseph 2016-02-28 at 03:19:59

image for Generating a secure random numbers using php7

Random numbers are useful when generating random passwords or numbers.

We have been using the rand() function to generate them but it does not generate a cryptographically secure value, php version seven (php7) introduces a new function random_int() which solves this issue.

It takes in two arguments and that is min value and max value and return a value in range to max, incusive.

For example


<?php
echo random_int(1, 100);
?>

This will output a random value greater or equal to 1 and less or equal to 100 (1 >= x <= 100)

Tags:
php

Search

Leave a comment

Fields with * are required
Your email address will not be displayed
1 + 4 =