﻿ PHP Math Exercise: Generate random 11 characters string of letters and numbers - w3resource

# PHP Math Exercises: Generate random 11 characters string of letters and numbers

## PHP math: Exercise-3 with Solution

Write a PHP script to generate random 11 characters string of letters and numbers.

Visual Presentation:

Sample Solution:

PHP Code:

``````<?php
\$x = rand(10e12, 10e16); // Generate a random number between 10^12 and 10^16
echo base_convert(\$x, 10, 36)."\n"; // Convert the random number to base-36 and echo it
?>
```
```

Output:

```3b6jfwh18v2
```

Explanation:

In the exercise above,

• \$x = rand(10e12, 10e16);: This line generates a random number between 10^12 and 10^16 using the "rand()" function. The range of the random number is specified using scientific notation, where '10e12' represents 10^12 and '10e16' represents 10^16.
• echo base_convert(\$x, 10, 36)."\n";: This line converts the generated random number '\$x' from base-10 (decimal) to base-36 using the "base_convert()" function. Base-36 uses the digits 0-9 and letters A-Z to represent numbers. The converted number is then echoed to the output, followed by a newline character ("\n").

Flowchart:

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿