Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/altaidevorg/rules-for-aiWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/altaidevorg/rules-for-ai/nnx_rngs)<a href="https://agentmods.dev/rules/altaidevorg/rules-for-ai/nnx_rngs"><img src="https://agentmods.dev/badge/rules/altaidevorg/rules-for-ai/nnx_rngs.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00028 | $0.04573 |
| Opus 5 | $0.00014 | $0.02286 |
| Sonnet 5 | $0.00006 | $0.00915 |
| Haiku 4.5 | $0.00003 | $0.00457 |
Grade A, and why
nnx_rngs scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 347 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Chapter 3: nnx.Rngs
In the previous chapter, we explored how nnx.Variable and nnx.VariableState manage state within nnx.Module instances. We saw specific variable types like nnx.Param and nnx.BatchStat. This chapter focuses on another crucial aspect of neural network initialization and certain layer types: managing randomness using nnx.Rngs.
Motivation: Explicit Randomness in JAX
JAX's functional programming paradigm requires explicit handling of Pseudo-Random Number Generator (PRNG) keys. Unlike stateful libraries where randomness might be implicit via a global seed, JAX functions need PRNG keys passed as arguments. Manually managing and splitting these keys across complex nested modules can become tedious and error-prone.
Flax NNX introduces nnx.Rngs to streamline PRNG key management. It acts as a central container for different "streams" of randomness (e.g., one for parameter initialization, another for dropout). Modules request keys from specific streams as needed, and nnx.Rngs ensures unique keys are generated sequentially, maintaining reproducibility and fitting within JAX's functional requirements.
Central Use Case: Initializing Modules with Randomness
Most neural networks require random initialization for parameters, and some layers (like dropout) require randomness during the forward pass. nnx.Rngs is typically instantiated once at the top level and passed down the module hierarchy during construction.
import jax
import jax.numpy as jnp
from flax import nnx
from flax.nnx.nn import Linear, Dropout # Using pre-built NNX layers
class SimpleMLP(nnx.Module):
def __init__(self, din: int, dhidden: int, dout: int, *, rngs: nnx.Rngs):
# Pass the Rngs instance down to submodules
self.linear1 = Linear(din, dhidden, rngs=rngs)
# Dropout requires an RNG key for its mask generation setup
self.dropout = Dropout(rate=0.5, rngs=rngs)
self.linear2 = Linear(dhidden, dout, rngs=rngs)
def __call__(self, x: jax.Array, *, train: bool) -> jax.Array:
x = self.linear1(x)
x = nnx.relu(x)
# Pass deterministic flag to control dropout behavior
x = self.dropout(x, deterministic=not train)
x = self.linear2(x)
return x
# 1. Instantiate Rngs at the top level with a base seed (0)
# Specify different seeds for specific streams if needed.
top_level_rngs = nnx.Rngs(default=0, params=1, dropout=2)
# 2. Pass the Rngs instance during MLP initialization
mlp = SimpleMLP(din=10, dhidden=20, dout=5, rngs=top_level_rngs)
# Create dummy data
x = jnp.ones((1, 10))
# Run in training mode (dropout active)
# Dropout internally uses its 'dropout' stream key, implicitly managed by nnx.Dropout
y_train = mlp(x, train=True)
# Run in evaluation mode (dropout inactive)
y_eval = mlp(x, train=False)
print(f"MLP Output shape (train): {y_train.shape}")
print(f"MLP Output shape (eval): {y_eval.shape}")
# Inspect the state to see the RngState variables managed internally
mlp_state = nnx.state(mlp)
print("\nMLP State showing RngState for Dropout:")
# Note: Linear layers use 'params' stream *during init*, but don't store RngState after.
# Dropout stores RngState to generate masks *during calls*.
print(mlp_state['dropout'])
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 8d ago First seen · 347 lines · 28 tokens per session scan A 785565082d08
nnx_rngs is a cursor rule published in the GitHub repository altaidevorg/rules-for-ai (2 stars, last pushed 1y ago), licensed MIT. It adds 28 tokens to every session and 4,573 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other cursor rules, from other repositories
tensorflow
TensorFlow: Keras, model training, production deployment.
006_Program_of_Thought_Tutorial
DSPY 3 Program of Thought Tutorial - Production code reasoning system from official DSPy 3.0.1 tutorial.
standards-data-eng
Mandatory standards for Python and SQL data pipelines.
ponytail
Ponytail, lazy senior dev mode. Always pick the simplest solution that works.
angular-20
This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.
dev-standard
Apache Superset development standards and guidelines for Cursor IDE.