FastPrepXOR Pseudorandom Sequence
Problems/XOR Pseudorandom Sequence

XOR Pseudorandom Sequence

Baseten logoBaseten● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Baseten full-time phone screen. The report asks for a random number generator that uses XOR bit operations. We chose the xorshift32 formula, the width of the state, the rules for the seed, and the interface for the sequence. Our version is about 70% the same as the reported question.

Generate a sequence of numbers by updating a 32-bit state with XOR and shifts, using the standard xorshift32 steps. Begin with the nonzero unsigned state seed.

  1. state = (state XOR (state << 13)) modulo 2^32.
  2. state = state XOR (state >> 17), using a logical right shift.
  3. state = (state XOR (state << 5)) modulo 2^32.

After all three updates, emit the new unsigned state. Repeat for count consecutive updates and return those values in order. The initial seed itself is not an emitted value. A zero count returns an empty array.

These steps fully define the generator. Complete xorRandomSequence.

Function

xorRandomSequence(seed: long, count: int) → long[]

Examples

Example 1

seed = 1count = 5return = [270369,67634689,2647435461,307599695,2398689233]

The first transition emits 270369; each following transition uses the previously emitted state.

Example 2

seed = 4294967295count = 2return = [253983,4228382207]

The seed has all 32 bits set. Outputs remain unsigned even when bit 31 is set.

Constraints

  • 1 <= seed <= 2^32 - 1.
  • 0 <= count <= 2000.
  • Keep the low 32 bits after each left-shift XOR. Right shift inserts zero bits.
  • Return unsigned values as nonnegative 64-bit integers in [0,2^32 - 1].

More Baseten interview questions

  • RNG-Based Tree Document CodecPHONE SCREEN · Seen Oct 2026
  • Single-Pass S-Expression ParserONSITE INTERVIEW · Seen Nov 2026
  • API Call Thread Pool ScheduleONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • CPU Register Bitwise OperationsHeadlands Technologies · PHONE SCREEN
  • Set and Clear BitsAMD · PHONE SCREEN
  • Clocked Counter with Reset and EnableXilinx · PHONE SCREEN
  • Out-of-Order TLV File ReassemblyApplied Intuition · PHONE SCREEN
  • Ordered IP FirewallDatabricks · PHONE SCREEN
  • CIDR IPv4 Range IteratorOpenAI · PHONE SCREEN
  • Three-Speaker Truth ConsistencySusquehanna International Group (SIG) · OA
  • Operations to Reduce a Binary String Value to ZeroMarshall Wace · OA
  • Repeated Mirror XORMathWorks · OA
  • Competitive ForagingAkuna Capital · OA

Baseten interview experiences

  • Baseten Experienced MLE Onsite: 1 Experience
See Baseten hiring insights
Saved
class Solution {
    public long[] xorRandomSequence(long seed, int count) {
        // Write your code here.
    }
}
Checking account…