-11

I am new to laravel . I want to know what does rand(1,6) means ?

if (rand(1,6) < 5)
      { //some code
}

Could someone please brief it in detail .

Komal Raja
  • 29
  • 4
  • 4
    This would have been trivial for you to find this yourself if you had done some basic research, like google. "php rand()" – M. Eriksson Jul 03 '20 at 06:26

2 Answers2

4

This is a basic php function - https://www.php.net/manual/en/function.rand.php

It gets a pseudo-random integer from 1 to 6, and if the random number is less than 5 the code is run.

qBen_Plays
  • 262
  • 2
  • 9
0

It's a php function to generate random numbers between the two given parameters

Here the chance will be 2/3 that the if statement gets executed

https://www.php.net/manual/de/function.rand.php

EDIT:

The chance is 2/3 because the function will generate a random number between 1 and 6 -> 1, 2, 3, 4, 5 or 6 which means that there are 4 numbers smaller than 5. Thus our chance is 4 numbers of 6 numbers (=> 4/6) which is equal to 2/3

CodingMoon
  • 11
  • 4