{"uid":"cap_X8DKRvCl6TavBp65NZ0Z1","slug":"delx-commerce-weighted-random-choice-42a0a29b","name":"Delx Commerce — Weighted Random Choice","description":"Pay-per-result APIs for agents. No signup. Exact price. Verifiable delivery. USDC on Base + Solana via x402.","url":"https://commerce.delx.ai/api/v1/x402/weighted-choice?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"items":{"type":"array","description":"Input field: items."},"weights":{"type":"array","description":"Input field: weights."}}},"responseSchema":{"type":"json","example":{"ok":true,"index":0,"choice":"a","schema":"delx/util-weighted-choice/v1","weight":1,"probability":0.25,"total_weight":4}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_K1iYVbUQy2bqSnQRM4d56","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Randomly selects one item from a list using weighted probabilities, returning the chosen item, its index, weight, and probability","exampleAgentPrompt":"Pick one item randomly from the list ['a','b','c','d'] where 'a' has weight 1, 'b' has weight 2, 'c' has weight 1, and 'd' has weight 4, and tell me which one was selected and the probability it had of being chosen.","exampleUseCases":[{"title":"Weighted A/B test variant assignment","prompt":"I have three UI variants — 'control', 'variant_a', and 'variant_b' — and I want to show 'control' 50% of the time, 'variant_a' 30%, and 'variant_b' 20%. Pick one for this user session using weights 5, 3, and 2."},{"title":"Random prize tier selection for a giveaway","prompt":"I'm running a giveaway with three prize tiers: 'bronze', 'silver', and 'gold'. Bronze should come up most often, so give it weight 10, silver weight 3, and gold weight 1. Pick a prize tier for this winner."},{"title":"Randomized content recommendation with bias","prompt":"I want to recommend one content category to a user — 'news', 'sports', 'entertainment', or 'tech' — where news is twice as likely as the others. Use weights 2, 1, 1, 1 and tell me which category was selected and how likely it was."}],"resultDescription":"Returns a JSON object with ok (boolean), the chosen item as 'choice', its zero-based 'index' in the input array, its individual 'weight', the computed 'probability' (weight divided by total), and 'total_weight' summed across all items. Also includes a schema identifier 'delx/util-weighted-choice/v1'.","failureModes":["Mismatched array lengths between items and weights — likely returns an error or undefined behavior","Empty items or weights arrays — API may return an error response","Non-numeric weights — validation failure expected","Network or payment failure via x402 protocol — call not executed, no charge"],"whenToPreferThis":"Use this endpoint when you need a stateless, pay-per-call weighted random selection with cryptographically verifiable delivery and no signup overhead. Prefer it over rolling your own PRNG when you need an auditable, reproducible random draw billed per use via USDC on Base or Solana. Ideal for agents that need probabilistic branching, A/B routing, weighted lotteries, or randomized content selection in a pipeline without managing server infrastructure.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-02T01:38:31.392Z","isFirstParty":false,"canonicalSlug":"delx-commerce-weighted-random-choice-42a0a29b"}