ตัวเลขสุ่มและเมล็ดสุ่ม
สร้างข้อมูลสังเคราะห์ที่ทำซ้ำผลลัพธ์ได้ด้วย NumPy
ตัวเลขสุ่มและเมล็ดสุ่ม เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Generate Random Data
Real datasets are not always handy. Random numbers let you build test data, simulate scenarios, and shuffle samples on demand.
The Modern Generator
Start by creating a generator with default_rng. This is the current, recommended way to make random numbers in NumPy.
rng = np.random.default_rng()Uniform Floats
Call random on the generator for floats between 0 and 1. Pass a size to get a whole array at once.
rng.random(3) # 3 floats in [0, 1)Random Integers
Use integers to draw whole numbers in a range. The low bound is included and the high bound is excluded.
rng.integers(1, 7, size=5) # like dice rollsDraw From a Normal Curve
The normal method samples a bell curve. Give it a mean and a standard deviation to shape the spread of values.
rng.normal(0, 1, size=4)The Problem With Randomness
Run random code twice and you get different numbers. That breaks reproducibility when a teammate cannot recreate your results.
Seeds Fix the Sequence
A seed sets the generator to a known start. Same seed means the exact same numbers, every single run.
rng = np.random.default_rng(42)Same Seed, Same Output
Two generators built with seed 42 produce identical arrays. That is how notebooks stay reproducible across machines.
a = np.random.default_rng(42).random(3)
b = np.random.default_rng(42).random(3) # a == bShuffle and Sample
Generators also shuffle arrays and pick random samples with choice, perfect for splitting data or drawing test cases.
rng.choice([10, 20, 30], size=2)Why It Matters for Science
Seeding makes experiments repeatable. Reviewers can rerun your code and confirm they see the very same outcome you reported.
Prefer the New API
You may still see the older np.random.seed style. New code should prefer the default_rng generator for cleaner, safer randomness.
Quick Check
A colleague reruns your notebook and gets different random results.
Randomness Recap
You generated floats, ints, and normal samples, then locked them with a seed so your results are reproducible anywhere. 🎲
คำถามที่พบบ่อย
บทเรียน “ตัวเลขสุ่มและเมล็ดสุ่ม” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ตัวเลขสุ่มและเมล็ดสุ่ม” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ตัวเลขสุ่มและเมล็ดสุ่ม”
สร้างข้อมูลสังเคราะห์ที่ทำซ้ำผลลัพธ์ได้ด้วย NumPy คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ตัวเลขสุ่มและเมล็ดสุ่ม” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม
ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ปรับรูปร่างและทำอาร์เรย์ให้แบน
- ผลรวม ค่าเฉลี่ย และเคล็ดลับแกน
- หน้ากากบูลีนสำหรับการเลือก
- ตัวเลขสุ่มและเมล็ดสุ่ม