190k views
5 votes
Write an expression that obtains a random integer between 34 and 55. Write an expression that obtains a random integer between 0 and 999. Write an expression that obtains a random number between 5.5 and 55.5.

User Thina
by
8.2k points

1 Answer

3 votes

Final answer:

To generate random integers in the given ranges, 'randInt' functions can be used, while generating a non-integer random number requires combining an integer generation with a random decimal addition.

Step-by-step explanation:

Generating Random Numbers

To obtain a random integer between 34 and 55, you can use randInt(34, 55) in a calculator or a programming language that supports such a function. To obtain a random integer between 0 and 999, use the expression randInt(0, 999). For obtaining a random number between 5.5 and 55.5, we cannot directly use randInt as it is for integers only. Instead, one can use a combination of generating a random integer and then adding a random decimal part, such as randInt(5, 55) + Math.random() in JavaScript, for example (assuming your environment has a Math.random function that generates a random decimal between 0 and 1).

Rounding to one decimal place may be necessary if a single decimal point precision is required in the last case.

User Ahjmorton
by
8.1k points