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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Randomly generated numbers and arrays

Status
Not open for further replies.

aggro

Programmer
Jun 9, 2000
4
GB
Simple question - I have a piece of code to generate 3 random numbers and an array containing 3 elements. How can I pass the numbers into the elements of the array? Code would be useful here thanks!
 
int x; // your random number<br>int y[3]; // your array<br><br>// generate your randon number here<br>.<br>.<br>.<br><br>int Inc = 0; // for array<br><br>y[Inc] = x;<br>Inc++;<br><br>// generate next randon number here<br>.<br>.<br>.<br><br>y[Inc] = x;<br>Inc++;<br><br>// generate next randon number here<br>.<br>.<br>.<br><br>y[Inc] = x;<br>Inc++;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Of course you really should put bound checks on <i>Inc</i>. If this isn't what you are looking for, give us some more details.<br> <p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
2ffat, the information you gave was what I needed thankyou, but during the number generation what do I need to put to assign the value to the 'x' variable?<br>Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top