Agent skill
numpy-random
Install this agent skill to your Project
npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/numpy-random
SKILL.md
Overview
NumPy's random module shifted from the legacy RandomState to the modern Generator API. This new approach provides better statistical properties, faster algorithms, and a robust system for parallel random number generation using SeedSequence.
When to Use
- Stochastic simulations requiring high-quality random bits.
- Shuffling datasets for machine learning training.
- Generating independent random streams for parallel computing workers.
- Creating reproducible experiments across different runs.
Decision Tree
- Starting a new project?
- Use
np.random.default_rng(). Do not usenp.random.seed().
- Use
- Need independent streams for multiple CPUs?
- Use
SeedSequence.spawn()to create children.
- Use
- Shuffling in-place?
- Use
rng.shuffle(arr). For a copy, userng.permuted(arr).
- Use
Workflows
-
Parallel Random Stream Generation
- Initialize a SeedSequence with a high-quality entropy source.
- Use the
.spawn(n)method to create independent seed sequences for workers. - Instantiate a new Generator for each worker using its specific child sequence.
-
Reproducible Simulation Setup
- Obtain a 128-bit seed (e.g., using
secrets.randbits(128)). - Initialize the generator:
rng = np.random.default_rng(seed). - Log the seed to allow exact reproduction of the stochastic results in future runs.
- Obtain a 128-bit seed (e.g., using
-
In-Place Array Shuffling
- Create a Generator instance.
- Pass an existing array to
rng.shuffle(arr)to modify it in-place. - Specify the
axisparameter if only certain dimensions (e.g., rows) should be rearranged.
Non-Obvious Insights
- Legacy Discouragement:
RandomStateis essentially in maintenance mode;Generatoris faster and has better statistical distribution qualities. - Small Seed Limitation: Seeding with small integers (0-100) limits the reachable state space;
SeedSequenceensures high-entropy starting states. - Bitstream Instability: Even with the same seed, the bitstream is not guaranteed to be identical across different NumPy versions due to algorithmic improvements.
Evidence
- "In general, users will create a Generator instance with default_rng and call the various methods on it to obtain samples." Source
- "SeedSequence mixes sources of entropy in a reproducible way to set the initial state for independent and very probably non-overlapping BitGenerators." Source
Scripts
scripts/numpy-random_tool.py: Implements parallel seed spawning and reproducible RNG.scripts/numpy-random_tool.js: Basic random sampling logic.
Dependencies
numpy(Python)
References
- references/README.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
prompt-engineering
Comprehensive prompt engineering techniques for Claude models. Use this skill when crafting, optimizing, or debugging prompts for Claude API, Claude Code, or any Claude-powered application. Covers system prompts, role prompting, multishot examples, chain of thought, XML structuring, long context handling, extended thinking, prompt chaining, Claude 4.x-specific best practices, and agentic orchestration including subagents, agent loops, skills, MCP integration, and multi-agent workflows.
adk-rag-agent
Build RAG (Retrieval-Augmented Generation) agents with Google ADK and Vertex AI RAG Engine. Use when implementing document Q&A, knowledge base search, or citation-backed responses. Covers VertexAiRagRetrieval tool, corpus setup, and citation formatting.
headless-cli-agents
Build agentic systems using Claude CLI in headless mode or the Claude Agent SDK. Use when building automation pipelines, CI/CD integrations, multi-agent orchestration, or programmatic Claude interactions. Covers CLI flags (-p, --output-format), session management (--resume, --continue), Python SDK (claude-agent-sdk), custom tools, and agent loop patterns.
notion-knowledge-capture
Capture conversations and decisions into structured Notion pages; use when turning chats/notes into wiki entries, how-tos, decisions, or FAQs with proper linking.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
gh-fix-ci
Inspect GitHub PR checks with gh, pull failing GitHub Actions logs, summarize failure context, then create a fix plan and implement after user approval. Use when a user asks to debug or fix failing PR CI/CD checks on GitHub Actions and wants a plan + code changes; for external checks (e.g., Buildkite), only report the details URL and mark them out of scope.
Didn't find tool you were looking for?