what is random?

StudioOne Repo - wpHakka wordpress underground, plugins, security, fixes, comments, and lots of sarcasm

RANDOM is a quite common word, like in life as in programming languages, but it also has human interpretations which can lead to false expectations . . .

a random function doesn’t necessary return a unique result, it should be seen as unpredictable result, let’s say you have 10 words and want a random pick, the random functions does it, but, eventually you will see ten times in a row the first word, pretty much like roulette

since that might not be desired, e.g. on a commercial site you want to show on each visit another “random product” to the customers, but not repeatedly the same product

so now we see that we are not exactly want it to be random, we want it do be different from last time, in order to get that done we need to query the product table, create the product list and pick one to show it and take it out of the list, next visit gets 100% another product, because the former isn’t in the list anymore

we wrote our stray function as valid alternative to common random functions

recap, we create a list, pick one after the other, when the list is empty we create a new one, we repeat the process as many times we want

of course, seeing the same product can still occure after refreshing the list and starting over, depending on the number of products you have it happens sooner or later, that the same product hits the same visitor is far less possible than it happens with a simple random function

random versus our stray function is a concept, which one you use depends on the desired outcome



hakka quote … asking AI for advice on CSS is the same as asking a blind man to cut your hair

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *