set.seed() का उपयोग
set.seed R के random choices का starting point fix करता है ताकि आपको हर बार same random picks मिलें। यह सबके लिए exactly same तरीके से एक deck shuffle करने जैसा है।
In this page:
Syntax
set.seed(seed_number)
sample(x, size)
set.seed()
set.seed(n) R के random number generator को एक fixed, known starting state से initialize करता है, sample() या rnorm() जैसे बाद के "random" operations को runs के आर-पार reproducible बनाते हुए।
इसके बिना, हर run अलग random results produce करता है। एक seed set करना reproducible analysis share करने और randomness involve करने वाला code test करने के लिए essential है।
Note:
जिस code को आप दूसरों के exactly reproduce करने लायक बनाना चाहें उसमें किसी भी random operation से पहले हमेशा set.seed() call करें।
उदाहरण: set.seed()
set.seed(123)
print(sample(1:100, 5))
set.seed(123)
print(sample(1:100, 5)) # identical output, same seed
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- random numbers already draw होने के बाद
set.seed()call करना, इसलिए इनका इन पर कोई effect नहीं। - top पर एक बार seed set करना और हर बाद की call के repeat होने की उम्मीद करना, जब हर draw के बाद sequence जारी रहता है।
- एक seed इस्तेमाल करना और फिर यह मान लेना कि numbers truly random हैं, जब वे reproducible pseudo-random numbers हैं।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: