RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1072 | Replies: 2
Reply
Join Date: Jul 2006
Posts: 2
Reputation: krayJ is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
krayJ krayJ is offline Offline
Newbie Poster

Random sequence in an array?

  #1  
Jul 27th, 2006
Hello, I am a beginner at C++ and need some help with arrays..


- I need to create a function that returns a random number from a sequence of 4 #s.

- Then I have to loop it 1000x and print the frequency of those 4 #s.

So far I have:
const int n=4, ntimes=1000;
int freq[n]={0};
short int seq[]={11,35,99,132};

and I understand I need to use:

rand(freq, n, ntimes);

and to output:

cout<<rndseq[i]<<" occured "<<freq[i]<<" times"<<endl;

Obviously, I havent had much time to work on it yet. I tried reading up on arrays but I did not find much on this specifically..

I just need someone to help me start off on the right foot. I'm not expecting anyone to fully write it for me. Just some pointers please. Much appreciated.
Last edited by krayJ : Jul 27th, 2006 at 4:18 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Random sequence in an array?

  #2  
Jul 27th, 2006
Try organising your thoughts on paper first. If you know what flow charts are try drawing one.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 472
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 44
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: Random sequence in an array?

  #3  
Jul 27th, 2006
[De-cloak] :eek:

Assuming that your array of random numbers is constant, then your 4 elements are always indexed by the numbers 0,1,2,3 .... that should make life pretty simple Start it out as a simple random-number picker for the numbers 0-3 and carry on from there.

[/De-cloak]
Last edited by Bench : Jul 27th, 2006 at 9:01 pm.
¿umop apisdn upside down?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:46 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC