Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:create:functions:random_p [13.01.2015 16:55] – [Example 1] alexander.ritteren:create:functions:random_p [13.01.2015 16:59] (current) – [random_p()] alexander.ritter
Line 10: Line 10:
  
  
-**Note:** Use the function [[:en:create:functions:put|put()]]''to save the drawn value in the data record.+**Note:** Use the function ''[[:en:create:functions:put|put()]]'' to save the drawn value in the data record.
  
 ===== 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 = getItems('PS19', 'min', 2);+$watched = getItems('PS19', 'min', 2);
 // 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('end');   goToPage('end');
 } }
 // 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 = array(); +$pWatched = array(); 
-foreach ($genutzt as $sender) { +foreach ($watched as $station) { 
-  $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('PS20_01', $fokus);+put('PS20_01', $focus);
 </code> </code>
en/create/functions/random_p.txt · Last modified: 13.01.2015 16:59 by alexander.ritter
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki