How can i more control rand()

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2004
Posts: 7,698
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 730
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How can i more control rand()

 
2
  #11
Jun 9th, 2009
>As I can say "Build an operating system." is a single step
It is, but you have to increase the granularity of your steps to come up with reasonable milestones. I find it somewhat humorous that you compare building an operating system to a trivial twenty line homework program.

>My recent interaction with low level languages are responsible for this.
That's a bad thing. Even at the lowest level you still need to keep an abstract view of your design.
Last edited by Narue; Jun 9th, 2009 at 11:15 am.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: How can i more control rand()

 
1
  #12
Jun 9th, 2009
A day ago csurfer's algorithm solved the problem. That's "pipelined" version:
  1. int i, j = rand()%20;
  2. for (i = 0; i < 20; i++)
  3. array[i] = (i != j)*(rand()%9 + 1);
In addition: it's impossible to add another level of randomness by random shuffles or other tricks while we are using the same (extremely bad ) rand() generator.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: How can i more control rand()

 
0
  #13
Jun 9th, 2009
>I find it somewhat humorous that you compare building an operating system to a
>trivial twenty line homework program.
Then my purpose was solved.

>That's a bad thing. Even at the lowest level you still need to keep an abstract
>view of your design.
The program I was interacting with were very trivial ( prime number generator ). It was in a algorithm book. There, the author used a ASM, to demonstrate that what a high-level program assumes to be `a step' is actually a series of steps in machine code.
But you said it right, one should be able to `quantize' a step. It also varies from person to person and to which domain he is working.

>it's impossible to add another level of randomness by random shuffles or other
>tricks while we are using the same (extremely bad ) rand() generator.
She assumed a perfect random generator while making that remark, IMHO. And she was right too. More random calls will tend to dilate the variance. (of course, I am too, making this remark assuming a perfect random generator)
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,607
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: How can i more control rand()

 
0
  #14
Jun 9th, 2009
^ so.... whatever happened to June 6th?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: How can i more control rand()

 
0
  #15
Jun 9th, 2009
>^ so.... whatever happened to June 6th?
The plan stretched. Didn't bother to change the signature. (I know this is ignorance). Long story!!...
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,607
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: How can i more control rand()

 
0
  #16
Jun 10th, 2009
Long story!!
yeah, it usually is, when you try and quit the internets.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: How can i more control rand()

 
0
  #17
Jun 10th, 2009
>More random calls will tend to dilate the variance.
The variance of... what? We didn't estimate random sequence parameters in that case so the variance (or other moments) does not bear a relation to the sequence of 20 random numbers.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 17
Reputation: animefun2 has a little shameless behaviour in the past 
Solved Threads: 0
animefun2 animefun2 is offline Offline
Newbie Poster

Re: How can i more control rand()

 
0
  #18
Jun 12th, 2009
Thanks you guys for all your suggestions i solve the problem ^^
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 13
Reputation: seemant_sun is an unknown quantity at this point 
Solved Threads: 1
seemant_sun seemant_sun is offline Offline
Newbie Poster

Re: How can i more control rand()

 
0
  #19
Jun 12th, 2009
After filling the array make a loop to check whether there is any element with zero value
If not then fill it again if it is then break
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC