Re: [PHP-DEV] Re: Note added to rand
At 03:47 10-09-01, Sterling Hughes wrote: That's your opinion. Why do we have to change it, when people have been using it happily for all these years. That's not a very good reason. We'd be playing with PHP 3.0 today if that was the guideline :) What happened to adding a new random() function? Zeev -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] Re: Note added to rand
Note added by joey, text: My vote: +0 Suggestions/remarks: I'll take the proposal one piece at a time: Good idea :-) float random() / int random(min, max): If I understand correctly, the only way you'll know what kind of return the user is expecting is by counting args. That means if I just want a random number between LONG_MIN and LONG_MAX (what I expect *most* users of a random fuction are looking for), I have to use the longer format of random(min, max). This seems counter-intuitive... The most commonly used version should be the easiest to type. I'd rather see another function entirely for floats. O yes... oversight, indeed. It was a quick idea which I typed in... indeed, a separate function would be better. I thought that you should always give a range because it otherwise makes no sense. But indeed, LONG_MIN ... LONG_MAX does make sense. set_random(): This seems to be to go out of it's way to bring things back to the way they currently are. If they want to change the algorithm, and the algorithm is decided via an ini switch, they can use ini_set/ini_alter(). The primary goal here is to make it possible through a single function call to obtain a random number, is it not? Let random() seed itself. I wasn't clear. Usually, you do NOT call set_random(), indeed, ini-set is the way it is supposed to be. The only circumstance where you need set_random is when you want a specific seedalgorithm, for example while debugging, place it at the top of the script and you'll get identical numbers each call. There is a good idea here, IMHO, and that is to reduce the namespace by wrapping all possible PRNG's with a very thin wrapper, but I don't see any need to break BC or make this wrapper any fatter than it needs to be to serve the purpose. I'll return to this and the rest later, I need to go now, I'm supposed to assist in a workgroup... --Jeroen I'd rather see: new ini switch: rand_algoritm, defaults to mt. (I still think that mt is probably the best for most people, but I know that some people disagree...) new function: int random() : The same as if user called the desired rand() algoritm from user-space, with the added benefit of insuring that a sufficently unique seed has been provided first. I don't see a need for any of the rest of this, but I have said before that I'm really not very good at evaluating things from a Design point of view...I'm much better at evaluating implementations to judge how well the *fit* the proposed design. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] Re: Note added to rand
No number is truly random. That is the nature of computers. You can only generate a sequence of numbers, based on a seed. True (of course, I knew that already long ago...), but 1) You can obscure that by using time-varying seeds in order to get seemingly random numbers 2) You can resort to lavalamps, radiosources, monitoring mousemovements/keystrokes, etc etc My god, this is generating a random number, its nothing that complex, so lets not make it such. And, btw, if you want to use lcg, just use the lcg_value() function. Creating a language that is easy to use is very complex. It is very easy to create a language that is hard to use. That was and is my whole point. lcg_value() is another strange duck in the bite: it seeds itself automatically on startup, you cannot seed it yourself, and you can only get it to return rand() / RANDAX, not a integer range (the alg. returns integers!) We don't need PHP to support 15 different algorithms for generating random numbers, if you want that, move it into a php extension, but it doesn't belong in the core. But IMHO the interface needs to me facilitated in the core, otherwise you can't use other RNG's like you can use the core ones. There are 3 different RNG currently in the core! My proposal reduces the namespace-load to PHP to 2: random and set_random. If you want random numbers, you only have one function: random. If you place set_random at the top of any script, you will see that it garantees that the script will act identically on each call, because set_random controls all random! IMHO the power of PHP is it's intuitiveness in using it, and I don't think mt_srand(); mt_rand() is intuitive. Really, then why hasn't anyone complained as of yet? And this is the way it is done in other languages as well (C, Perl, Python). Why change what's working? If you really want, create a new extension, distributed externally, just like Perl has the Math::TrulyRandom module. Most people don't realize it is unnecessarily cumbersome. If you look at newbies code, you see they make all kind of mistakes in it, which would IMHO be reduced if it becomes simpler. Please understand me right, I find it very useful to have someone critically look at my proposal, but please be more specific. Right, those more specific comments belong on list :) I didn't Cc to php-dev, since I could be breaking the law... but you may forward this mail to it :-) I am. ;) -Sterling --Jeroen -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] Re: Note added to rand
People interested in rand can still visit http://www.A-Eskwadraat.nl/~jeroen/rand , but if you have something interesting to say you can of course also mail to php-dev! World Wide Web Cie [EMAIL PROTECTED] wrote: Note added by jmoore: My vote: ±1 :) Suggestions/remarks: I think that PHP should provide a nicer more intuative random number system, who wants to have to give a shit about seeding a random number generator etc, I think we should still leave mt_* and *rand() in place as for C programmers they brhave the way we expect which makes our lives easier as we dont have to think but for non C programmers a no brain random() function would be nice. I think that somthing should be done but I am unsure if your proposal is the best way to do it.. Ill try to think of somthing and add to this and then perhaps we can get a better discussion about this whole thing. /quote I like the suggestion to keep rand and srand in place for people used to it. If you want to do it the hard way, why not give them the possibility? I'm not sure wether this is valid for mt_rand etc too, but why not... they will stay for a while anyway because of BC. Keep me posted if you think of something else! --Jeroen -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] Re: Note added to rand
On Sun, 9 Sep 2001, Jeroen van Wolffelaar wrote: Well, I didn't see them agree to all that, but... You also can't really say rand() isn't thread safe. It is thread safe on quite a few platforms, rand() isn't thread safe, but only very few platforms (i.e., Microsoft's ISS etc) use threads. Apache does not use threads, so it has no problems with non-thread safe code. Agreed, this can be fixed without changing implementation. Yes, on some systems it is thread safe, to my knowledge, and as I said, rand_r() solves this on systems it isn't. and if we switch to rand_r() it will be thread-safe on most other platforms. How is it difficult to use for newbies? I really don't see that many support requests coming in regarding random number functionality. Just because people simply don't notice it isn't random :-). That's inherent to the nature of the function... you won't see it's wrong - easily. It is simply needless complicated now, as Zeev says, we shouldn't be handling the subject in such a techie manner. See also below. No number is truly random. That is the nature of computers. You can only generate a sequence of numbers, based on a seed. mt_rand() is fine as an alternative, but I'd prefer to keep the system rand() as the default. The pointe is that you can choose. And I really don't see why you should keep an inferior algorithm as default... please explain? That's your opinion. Why do we have to change it, when people have been using it happily for all these years. And I also said before that wether or not is should be a redesign will be discussed AFTER it has been agreed how the functions will behave in the future. It is more helpful by the way if you comment on the separete points in the proposal, which points don't you like? What I see as something acceptable: 1) Switch most of the functions to use the mt_rand functions, as you see, i've made the latest CVS export these functions, so its just a matter of changing the function names in the source. 2) Automatically generate the seed's, I'm not sure whether this should be done at module init or put a test in each function. Then just make the call to [mt_]srand() optional. An easier way around this might just be to make the argument to srand() optional, ie: srand(); Would just use the most random seed possible. I completely agree that that is the minimun that should be done. As you know, IMHO more should be done. The major reason I wanted this is to have the possibility to add extra random number generators, to start with, add the lcg generator to it, since it is simply just-another-generator! When you add another two functions, now we have a rand() and a random() functions, the latter fixing non-existant bugs in the former. My god, this is generating a random number, its nothing that complex, so lets not make it such. And, btw, if you want to use lcg, just use the lcg_value() function. We don't need PHP to support 15 different algorithms for generating random numbers, if you want that, move it into a php extension, but it doesn't belong in the core. My proposal reduces the namespace-load to PHP to 2: random and set_random. If you want random numbers, you only have one function: random. If you place set_random at the top of any script, you will see that it garantees that the script will act identically on each call, because set_random controls all random! IMHO the power of PHP is it's intuitiveness in using it, and I don't think mt_srand(); mt_rand() is intuitive. Really, then why hasn't anyone complained as of yet? And this is the way it is done in other languages as well (C, Perl, Python). Why change what's working? If you really want, create a new extension, distributed externally, just like Perl has the Math::TrulyRandom module. Please understand me right, I find it very useful to have someone critically look at my proposal, but please be more specific. Right, those more specific comments belong on list :) I didn't Cc to php-dev, since I could be breaking the law... but you may forward this mail to it :-) I am. ;) -Sterling -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]