לולאות for ב#C - עמוד 3 - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

לולאות for ב#C


eido300

Recommended Posts

  • תגובות 37
  • נוצר
  • תגובה אחרונה

1.זה כל הטעות שלי? או שיש עוד משהו?

2.למה באמת עדיך לשים את i ולא כמו שאני עשיתי?

תודה.

נ.ב. מצטר שאני משגע אתכם עם כל השאלות (ולא רק בדיון הזה), אבל אני פשוט רוצה להבין הכל ולא סתם לכתוב מה שאומרים לי.

קישור לתוכן
שתף באתרים אחרים

1. זהו.

2. כי רק ככה זה עושה באמת הגרלה אחידה - הסיכוי לקבל כל תוצאה אפשרית של ערבוב הקלפים הוא שווה. יש בויקיפדיה הסבר קצת יותר מעמיק (הוא דורש קצת הבנה בקומבינטוריקה):

http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Implementation_errors

Similarly, always selecting j from the entire range of valid array indices on every iteration also produces a result which is biased, albeit less obviously so. This can be seen from the fact that doing so yields nn distinct possible sequences of swaps, whereas there are only n! possible permutations of an n-element array. Since nn can never be evenly divisible by n! when n > 2 (as the latter is divisible by n−1, which shares no prime factors with n), some permutations must be produced by more of the nn sequences of swaps than others. As a concrete example of this bias, observe the distribution of possible outcomes of shuffling a three-element array [1, 2, 3]. There are 6 possible permutations of this array (3! = 6), but the algorithm produces 27 possible shuffles (33 = 27). In this case, [1, 2, 3], [3, 1, 2], and [3, 2, 1] each result from 4 of the 27 shuffles, while each of the remaining 3 permutations occurs in 5 of the 27 shuffles.

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.


×
  • צור חדש...