Random Numbers 0.9

Asked

Viewed 218 times

0

I am developing a numeric keyboard, however, when printing the variable num, the numbers get repeated, I’m trying to make them random.

<?php
for($i=0; $i<=9; $i++){
    $num = rand(0,9)
?>
    <button class='btn btn-default' style='margin-top: 5px'><?php echo $num;?></button>         
<?php } ?>

inserir a descrição da imagem aqui

  • 1

    Just one detail: you don’t want to generate random numbers. Numbers will always be the same. What you need is to scramble the data: shuffle.

  • I’m using PHP @Maniero

  • @Andersoncarloswoss exactly like that

  • 1

    It shall be duplicated: https://answall.com/q/183927/5878, or https://answall.com/q/31161/5878, or https://answall.com/q/102405/5878

  • With shuffle solved, thank you.

  • 2

    That’s what we call chameleon question, Because you ask one question and I want to know another. The way you asked it became explicit that you wanted to generate 10 random numbers without repetition within the range [0, 9]. It would generate the expected result and the solution was discussed in the questions linked by Maniero; the only thing is that it is not the simplest way to solve.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.