Answer the question
In order to leave comments, you need to log in
How to shuffle an array in a pseudo-random sequence?
Good afternoon!
Imagine that we have two entities, for example, articles (article A and article B)
Each article has an array of hashtags (if the articles belong to the same topic, then the arrays of hashtags are identical, if they are different, they are different), in our case article A and article B belong to the same topic.
There is a need to shuffle each array in a pseudo-random manner, so that the article A page always displays the hashtags in one order, and the article B page displays the hashtags in a different order. That is, the random shuffle algorithm should always return the same shuffle for the same article, but may return different shuffles for different articles.
Accordingly, for articles from different topics, the arrays will be different, but the principle of the same mixing for the same article should be preserved
. Obviously, sorting the array by randomly generated numbers will not work here.
There was an idea to generate numbers based on the unique article identifier (id of the form 2613221) and sort on them, but it is not entirely clear how to do this, given that the length of the hashtag array is unknown
. What other options can there be?
Answer the question
In order to leave comments, you need to log in
The random number generator already works based on some starting value (seed). So if you feed him the article ID, he will always stamp the same, but random set of numbers.
Yes, divide 1000000 by this id and run through the numbers after the decimal point. It is also important to get just a conditionally infinite, but the same sequence of numbers
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question