docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화

Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
This commit is contained in:
Antigravity Agent
2026-07-05 00:10:59 +09:00
parent a397bc4720
commit 1cfd3bbb56
1495 changed files with 68534 additions and 27 deletions
+78
View File
@@ -0,0 +1,78 @@
---
id: c-random-numbers
title: "C Random Numbers"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["rand() srand()", "seeding random", "dice roll example", "C 난수"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.85
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["c", "programming-language", "w3schools", "random", "stdlib"]
raw_sources: ["https://www.w3schools.com/c/c_random_numbers.php"]
applied_in: []
github_commit: ""
---
# [[C Random Numbers]]
## 🎯 한 줄 통찰 (One-line insight)
Without calling `srand()`, `rand()` produces the EXACT SAME sequence of numbers every single time the program runs — it's not "random" by default at all, just deterministic-looking — and the standard fix (seeding with `time(NULL)`) works only because the current time is itself always different, meaning C's "randomness" is really pseudo-randomness bootstrapped from an ever-changing external value. [S1]
## 🧠 핵심 개념 (Core concepts)
- **`rand()`** (from `<stdlib.h>`) — returns a random integer, but deterministic/repeatable unless seeded. [S1]
- **`srand(seed)`** — sets the starting point for `rand()`'s sequence; without it, the sequence repeats identically on every run. [S1]
- **Time as a seed** — `srand(time(NULL))` (requiring `<time.h>`) uses the current time as the seed since it's always changing, producing different sequences run to run. [S1]
- **Call `srand()` exactly once** — specifically at the start of `main()`, NOT repeatedly inside a loop (re-seeding inside a loop would reset the sequence and undermine randomness). [S1]
- **Range restriction via modulo** — `rand() % N` maps the result into the range `0` to `N-1`; adding an offset shifts the range further (e.g. `(rand() % 6) + 1` for 1-6). [S1]
## 📖 세부 내용 (Details)
- Unseeded rand() (repeats every run): `int r = rand(); printf("%d\n", r);`. [S1]
- Properly seeded rand(): `srand(time(NULL)); printf("%d\n", rand());` — different results each run. [S1]
- Restricting to a 0-9 range: `int x = rand() % 10; // 0..9`. [S1]
- Dice-roll simulation combining modulo and offset: `int dice1 = (rand() % 6) + 1; int dice2 = (rand() % 6) + 1; printf("You rolled %d and %d (total = %d)\n", dice1, dice2, dice1 + dice2);`. [S1]
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **시드 없이는 진짜 랜덤이 아님**: srand()를 호출하지 않으면 프로그램을 몇 번을 실행해도 항상 같은 숫자가 나온다는 점이 명시적으로 경고됨 — 진짜 다른 결과를 원하면 반드시 시드를 설정해야 함. [S1]
- **srand()는 반복문 안에서 재호출 금지**: main 시작 시 딱 한 번만 호출해야 하며, 루프 안에서 반복 호출하면 안 된다는 점이 팁으로 강조됨. [S1]
## 🛠️ 적용 사례 (Applied in summary)
주사위 두 개를 굴려 1-6 범위의 숫자를 뽑고 합계를 계산하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
## 💻 코드 패턴 (Code patterns)
Simulating a dice roll using rand(), modulo, and an offset (C):
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(NULL)); // seed once, with the current time
int dice1 = (rand() % 6) + 1;
int dice2 = (rand() % 6) + 1;
printf("You rolled %d and %d (total = %d)\n", dice1, dice2, dice1 + dice2);
return 0;
}
```
## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.85
- **중복 검사 결과:** 신규 생성 (New discovery)
## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C Tutorial]]
- **관련 개념:** [[C Math]], [[C Date Time]], [[C Booleans]]
- **참조 맥락:** 수학 및 난수 섹션 마지막 — 불리언(Booleans) 섹션으로 이어짐.
## 📚 출처 (Sources)
- [S1] W3Schools — C Random Numbers — https://www.w3schools.com/c/c_random_numbers.php
## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C Random Numbers" page (Astra wiki-curation, P-Reinforce v3.1 format).