This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:create:functions:random_p [13.01.2015 16:55] – [Example 1] alexander.ritter | en:create:functions:random_p [13.01.2015 16:59] (current) – [random_p()] alexander.ritter | ||
---|---|---|---|
Line 10: | Line 10: | ||
- | **Note:** Use the function [[: | + | **Note:** Use the function |
===== Example 1 ===== | ===== Example 1 ===== | ||
Line 75: | Line 75: | ||
One of the television stations watched at least rarely should now be selected at random. However, preference should be given to television stations 2, 5 and 6. | One of the television stations watched at least rarely should now be selected at random. However, preference should be given to television stations 2, 5 and 6. | ||
- | |||
- | Nun soll aus den Sendern, die mindestens selten genutzt werden, zufällig einer ausgewählt werden. Allerdings sollten die Sender 2, 5 und 6 dabei bevorzugt werden. | ||
<code php> | <code php> | ||
// Create a list in which all television stations watched appear | // Create a list in which all television stations watched appear | ||
- | $genutzt | + | $watched |
// If no station is watched, the survey is over | // If no station is watched, the survey is over | ||
- | if (count($genutzt) < 1) { | + | if (count($watched) < 1) { |
goToPage(' | goToPage(' | ||
} | } | ||
// Define probabilities for the various stations | // Define probabilities for the various stations | ||
- | $pAlle = array( | + | $pAll = array( |
1 => 10, 2 => 20, 3 => 10, 4 => 10, | 1 => 10, 2 => 20, 3 => 10, 4 => 10, | ||
5 => 20, 6 => 30, 7 => 10 | 5 => 20, 6 => 30, 7 => 10 | ||
); | ); | ||
// A distribution must now be created for the stations watched | // A distribution must now be created for the stations watched | ||
- | $pGenutzt | + | $pWatched |
- | foreach ($genutzt | + | foreach ($watched |
- | $pGenutzt[$sender] = $pAlle[$sender]; | + | $pWatched[$station] = $pAll[$station]; |
} | } | ||
// Weighted random selection from the stations watched | // Weighted random selection from the stations watched | ||
- | $fokus = random_p($pGenutzt); | + | $focus = random_p($pWatched); |
// Store the subject matter | // Store the subject matter | ||
- | put(' | + | put(' |
</ | </ |