Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random and negative numbers

I have to generate numbers in range [-100; +2000] in c++. How can I do this with rand if there is only positive numbers available? Are there any fast ways?

like image 868
Max Frai Avatar asked Sep 30 '10 12:09

Max Frai


People also ask

How do you get a negative number from Rand?

Randomize negative decimal numbers You can use this formula =RAND()*(X-Y)Y (X and Y indicate any negative numbers, and X<Y), here, I type generate =RAND()*(-80+30)-30 and press Enter key, if you need, you can drag the fill handle to apply the formula to a range.

How do you randomly generate a negative number in Java?

The correct code is int rand = new Random(). nextInt((30 - 20) + 1) + 20; .

What is random number example?

Random numbers are almost always derived from a set of single-digit decimal numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The task of generating random digits from that set of numbers by physical means is not trivial.

Why is 17 the most common random number?

Seventeen is: Described at MIT as 'the least random number', according to the Jargon File. This is supposedly because in a study where respondents were asked to choose a random number from 1 to 20, 17 was the most common choice. This study has been repeated a number of times.


1 Answers

Generate a random number between 0 and 2100, and subtract 100.

like image 152
Jez Avatar answered Sep 19 '22 08:09

Jez