Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RANDOM SELECTION OF NUMBERS i.e MONTE CARLO

Status
Not open for further replies.

ankoump

Programmer
May 29, 2002
11
0
0
DE
Does anyone know how to write code in C++ that could allow a selection of numbers to be selected between two values.
for example i wish for a code that would allow any value to be selected between 2 and 30 for various iterations
 
Well, let's say you want to generate a value between a and b. What you could do is generate a number between 0 and (b-a) and than adding it to a. This way your smallest number will be a and your biggest will be b. Hope that helps. Remember that Visual C doesn't have the random() and randomize() functions so you'll have to use srand() and rand(). For more detail on these 2 functions see thread116-275510

Radu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top