Function Sampler
Sample and plot points from a 1D or 2D density expression with density validation and CSV export.
About this tool
Draw independent pseudo-random samples from a finite-domain density proportional to f. f need not integrate to one, but must be finite and non-negative. In both 1D and 2D, rejection sampling proposes uniform coordinates and accepts with probability f/M.
You must supply a valid upper bound M over the entire domain. Larger M remains correct but is slower. Evaluated violations discard the whole run; checking a finite grid and random proposals cannot certify an arbitrary expression between checked points. Examples provide known bounds. Seed reproduces the same points; sets are consecutive blocks of one seeded stream.
Blue histogram bars use all samples. The gray comparison integrates 16 subintervals per bin with the trapezoid rule and normalizes the approximate mass; it is a numerical guide, not an exact certificate. The 2D plot shows at most the first 5,000 points. CSV preserves every coordinate at round-trip precision; PNG includes the actual parameters. The 2D axes use equal units on screen; extremely thin domains may become smaller than one screen pixel.
Expressions support x, y (2D), pi, e, scientific notation, + − * / ^ and **, parentheses, and pure math functions such as exp, log, sqrt, sin, cos, abs, min/max and pow. Exponentiation binds before unary minus and is right-associative. Use decimal points in expressions; numeric fields also accept decimal commas.
Limits: 512 expression characters, 128 tokens, 32 parser nesting levels; 100,000 samples per set, 200,000 total, two million proposals per run, coordinates within ±1e100. A worker keeps the page responsive and Cancel terminates it. Extreme/narrow densities may fail the proposal budget or be missed by the display guide. Finite floating-point coordinates and the seeded generator are unsuitable for cryptography.
Sample starts the first calculation. Subsequent changes update after a short typing pause using the same seed. Cancel stops the worker and automatic updates until Sample is used again. Hidden pending work stops. Only raw inputs, inactive fields and open panels are retained locally; reload starts without generated samples, plots or results.