> ## Documentation Index > Fetch the complete documentation index at: https://bunny.net/docs/llms.txt > Use this file to discover all available pages before exploring further. # Weighted traffic splitting > Send a set percentage of visitors to a second origin and keep each visitor on the same origin across requests. This script hashes a stable key (the client IP) into a 0-99 bucket and routes by percentage. The same key always lands in the same bucket, so a visitor stays on one origin across requests. ```typescript theme={null} import * as BunnySDK from "@bunny.net/edgescript-sdk"; const ORIGINS = { a: "https://origin-a.example.com", b: "https://origin-b.example.com", }; const B_PERCENTAGE = 10; // send 10% of visitors to origin B // Polynomial string hash (Java String.hashCode style), mapped into a 0-99 bucket function bucket(key: string): "a" | "b" { let h = 0; for (let i = 0; i < key.length; i++) { h = (h * 31 + key.charCodeAt(i)) >>> 0; } return h % 100 < B_PERCENTAGE ? "b" : "a"; } BunnySDK.net.http.serve(async (request: Request): Promise => { const ip = request.headers.get("x-forwarded-for") ?? "0.0.0.0"; const variant = bucket(ip); const target = new URL(request.url); const origin = new URL(ORIGINS[variant]); target.protocol = origin.protocol; target.host = origin.host; return fetch(new Request(target, request)); }); ``` Adjust `B_PERCENTAGE` to change the split. To pin on something other than the client IP, such as a cookie or a header, hash that value instead. This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.