← Back to R Course | Chapter 9: Statistics | Lesson 6 of 7

set.seed() का उपयोग

set.seed R के random choices का starting point fix करता है ताकि आपको हर बार same random picks मिलें। यह सबके लिए exactly same तरीके से एक deck shuffle करने जैसा है।

In this page:

  1. set.seed()
Syntax
r
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()

markup
set.seed(123)
print(sample(1:100, 5))

set.seed(123)
print(sample(1:100, 5))  # identical output, same seed
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. #}
आम गलतियां
  1. random numbers already draw होने के बाद set.seed() call करना, इसलिए इनका इन पर कोई effect नहीं।
  2. top पर एक बार seed set करना और हर बाद की call के repeat होने की उम्मीद करना, जब हर draw के बाद sequence जारी रहता है।
  3. एक seed इस्तेमाल करना और फिर यह मान लेना कि numbers truly random हैं, जब वे reproducible pseudo-random numbers हैं।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.