[SOLVED] rand C prog and not being ran when called.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How I am testing this is with a cli program. Each time I execute it on the cli (so maybe that maybe way it is always the same I do not know, I just thought of that),
but I just have it calling that function each time then printf the values each time and it keeps coming up the same.
wait ....
Ok I just set it up to set a random color on the desktop while it is still running via a timer so that works.
it is just that the color will not change whenever I call for it get_random_color(); it gets a random color, sets it, the program exits,
run it again and i get the same color, always.
this is on the timer.
Code:
// -c different image -rc random color -D timer time images located
// each timer set diff each timer set set to 2 sec
$> ./mhsetroot -c -rc -g 100x100 -D 2 /media/data/test
// -g 100x100 to make that image smaller so I can see color changes
// and be sure it still setting a different image each time.
in trimmer set_random_colors
r 0 g 151 b 162 a 255
in trimmer set_random_colors
r 0 g 83 b 190 a 255
it is just that the color will not change whenever I call for it get_random_color(); it gets a random color, sets it, the program exits,
run it again and i get the same color, always.
From man 3 rand...
Code:
...rand() returns a pseudo-random integer in the range [0, RAND_MAX]. The seedp argument is
a pointer to an unsigned int that is used to store state between calls. If rand_r() is called with the
same initial value for the integer pointed to by seedp, and that value is not modified between calls,
then the same pseudo-random sequence will result.
Quote:
Originally Posted by BW-userx
red stays at zero as well there. why? anyone?
The reason for rc.r not being set should be obvious:
yeaaaaahhhhhh I think I got it figured out.
that is just the first set of randoms that get got on first time calling. so it is always going to be the same. ga duha
Code:
init_system_options r 0 g 0 b 0 a 0
OPTIONS: r 0 g 151 b 162 a 255
even calling twice before setting it I bet will get the same results .
mod:
@astrogeek
I just read yours after posting.
I'll just make a note to the program spit out info mess best used when cycling images with colors or just colors. (timer)
yep: stupid drop down list pick one thinking you got the right one, but didn't (human) error.
I switched from greny to codeblocks and not use to this one yet. excuse or reason?
It has nothing to do with your editor or IDE, that is just another excuse.
It has to do with the fact that you continue to post without doing even basic troubleshooting of your own, before performing even basic search of the documentation, and continuing to ask others to troubleshoot your application code, rather than expending effort of your own.
Let us be very clear - had you once read the man page for rand(), or performed even a simple online search for "C rand() function", you could not have missed how that works. No excuses, please.
And had you even once actually looked at the single line in your code which assigns the value for your integer variable, you would not have asked why the value seems not to be assigned. And had you actually read my original post, you would not have asked that question twice.
This behavior must stop - now, not later.
You often claim to be a novice at C programming, running when you should be walking, and using LQ as a crutch. Yet you continue to attempt to write your applications without stopping to gain the deficient knowledge of the language you are using, often ignoring the best advice of others to not do so. Well, no more please.
First, it is obvious that you need a better understanding of basic use and troubleshooting of the C language.
There is a sticky thread at the top of the Programming forum, C/C++ Tutorials. It has many excellent tutorials and reference links for C/C++ - use it! It has a few bad links, but it has a wealth of information, online references, tutorials and free books. Read them, and understand! If you have difficulty understanding something about the language - this is the place to ask, after trying to figure it out yourself!
Here are a few from that list that you should start with:
There are many more! Further excuses for not knowing the basics will be frowned upon.
Next, there are the LQ posting guidelines with which you should be familiar by now. Again I refer you to the Site FAQ and Welcome page, which are the standard guide to participation here at LQ. Please read them.
You have much to offer LQ, and LQ has much to offer you. But this continued pattern of behavior is harmful to LQ and not beneficial for yourself or others, and must end. Please make the effort, now.
It has nothing to do with your editor or IDE, that is just another ...
yes it did have something to do with my editor, and human behavior and patterns.
I type in r g b a
then I go to type in r g b a again, my brain is already set up for this pattern because of the first instance of behavior.
then when the human goes to repeat this same pattern of r g b a, and then is given a helping hand via some fancy drop down list that already knows what that person is talking about. but instead of giving this person the same patten that he is already using the drop down list changes the sequence of the same pattern, their for making room for error.
therefore YES it does have a LOT to do with the editor. because it changed the pattern sequence I was using.
therefore,
it is not an excuse it is Human Error on both parties, first and foremost,
by the ones that wrote the editor, because it changes the pattern that the user has already set, making room for error. As a result the user now has to put up his or her guard to check for this deviation of the pattern that the user has already set.
And the user, because he or she is not ready to accept or look for this change, or has his or hers guard down, the editor then is the leading cause because he or she has not looking for this deviation in the same patten that they have already set in order to make the needed adjustments to correct the error of the person that wrote the editor that causes the editor to change the sequence of the same said pattern in the first place.
so errors occur due to the first error, the editor, not the user.
that link under "excuse" that you posted to justify your judgment on me had to do with link list, this is a complete different situation.
you're letting your emotions cloud your judgments.
No, it is not the editor, but probably yes. If that editor knows exactly who is typing, what was entered and sometimes the letters are jumping/moving/disappearing just because the editor knows the human in front of the monitor actually looking out of the window .... to check the weather.
contradiction really did you listen to yourself when you contradicted yourself in the same sentence?
now who is making some twisted example for an excuse of to try and justify keeping me in the wrong?
Quote:
If that editor knows exactly who is typing, what was entered and sometimes the letters are jumping/moving/disappearing just because the editor knows the human in front of the monitor actually looking out of the window .... to check the weather.
the moderator is never wrong. my butt. you and that other is no better then me. prone to error.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.