Random numbers

I’m new to both Laravel and php. Need some help with generating random numbers.

If checkbox 1 (exercise_choice_10) is selected a random number between 1-10 shall be generated.
If checkbox 2 (exercise_choice_20) is selected a random number between 11-20 shall be generated.
If checkbox 3 (exercise_choice_30) is selected a random number between 21-30 shall be generated.


<input type="checkbox" name="exercise_choice_10" value="10" {{ app('request')->input('exercise_choice_10') ? 'checked' : '' }}> Type 1</input></BR>
<input type="checkbox" name="exercise_choice_20" value="20" {{ app('request')->input('exercise_choice_20') ? 'checked' : '' }}> Type 2</input></BR>
<input type="checkbox" name="exercise_choice_30" value="30" {{ app('request')->input('exercise_choice_30') ? 'checked' : '' }}> Type 3</input></BR>



<form action="{{ route('exam.robot', ['course' => $course]) }}" method="post">
    <input type="checkbox" name="exercise_choice_10" value="10" {{ app('request')->input('exercise_choice_10') ? 'checked' : '' }}> Type 1</input></BR>
    <input type="checkbox" name="exercise_choice_20" value="20" {{ app('request')->input('exercise_choice_20') ? 'checked' : '' }}> Type 2</input></BR>
    <input type="checkbox" name="exercise_choice_30" value="30" {{ app('request')->input('exercise_choice_30') ? 'checked' : '' }}> Type 3</input></BR>
    </BR>
    <button class="button">Submit</button>
    </BR>
    </BR>

What happens if all three are checked? Should that be a radio button and not a checkbox?

https://www.w3schools.com/php/func_math_rand.asp

1 Like

Random number between 1-30

What is the REAL problem you are trying to solve by doing this?

And if only two checkboxes are checked? Also obviously you are missing the code to generate random numbers…

If checkbox 1 is checed a random number between 1 - 10 are generated.
If checkbox 2 is checed a random number between 11 - 20 are generated.
If checkbox 3 is checed a random number between 21 - 30 are generated.

Example:
If checkbox 1 & 2 is checed a random number between 1 - 20 are generated.
If checkbox 1 & 3 is checed a random number between 1 - 10 and 21 - 30 are generated.

You don’t seem to understand what I asked. WHY are you doing this? What is the overall task/problem that you need specific sets of random numbers?

1 Like

I get your question benanamen. Im trying to learn PHP.

then try harder. look at variables and isset here. make a maximum value (which will be 10, 20 or 30) based upon the result (calculated result) of isset analysis.

So you’ve got a nice list that you can compare to the inputs via Set Theory and use that as a key to get a range from a map.

I get learning the language. It’s just this isn’t a very realistic problem to solve. It’s actually easy to handle, but I would recommend a book and working through it, rather than random problems

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service