Current location: Hot Scripts Forums » Programming Languages » C/C++ » clever function!


clever function!

Reply
  #1 (permalink)  
Old 09-16-10, 01:38 AM
Morlaf Morlaf is offline
Newbie Coder
 
Join Date: Aug 2010
Posts: 20
Thanks: 4
Thanked 0 Times in 0 Posts
clever function!

I already have the following and it works famously:
function r_gen()
main()
{
r_gen()
r_gen()
r_gen()
//outputs three different random numbers!
}
rgen()
{
generate a random number, r such that 100<r<1
}


but ideally I need to be doing this:
function r_gen()
main()
{
int c=10;
r_gen()
...
int c=35;
r_gen()
...
int c=75;
r_gen()
//outputs 3 different numbers and weather or not they are greater than a number c, which is different in every case
}
rgen()
{
generate a random number, r such that 100<r<1
if (r>c){false;} else{true;}
}
is this possible???
so far, all attempts have failed. All help appreciated.
Reply With Quote
  #2 (permalink)  
Old 09-29-10, 01:01 PM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
I dont see any code that actually generates the random number with the rand() function.

If I understand you right, you should just generate a random number and assign it to c.

Then generate a new number to assign to b taking c as max: rand(c)

And again generate a new number for a using b : rand(b)

However if you set the max it can have the random number is no longer so random and it will tend to take numbers in the lower ranges.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #3 (permalink)  
Old 12-05-11, 03:47 PM
scept1c scept1c is offline
New Member
 
Join Date: Jul 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I think it's possible.. but you should try and make it possible...
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Javascript in a php page binarybird PHP 1 06-21-10 05:57 AM
[2005] StartPosition for CommonDialogs? tim8w Windows .NET Programming 10 01-08-09 03:39 AM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 01:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.