{
  "id": "random-access",
  "title": "Random Access",
  "lang": "en",
  "source_lang": "en",
  "summary": "Random access is the ability to read or write data at a specified location without traversing all preceding data, enabling efficient indexed operations in memory, storage, and data structures.",
  "category": "computer-science",
  "subcategory": "hardware",
  "type": "concept",
  "aliases": [
    "Random-access addressing"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/random-access/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/random-access/",
      "json": "https://aiwiki.page/zh/random-access.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Random access is a method of accessing stored data in which a particular location can be selected without reading or passing through all preceding locations. In computer science, it describes a capability of memory, storage devices, files, and data structures. In its strictest sense, access takes approximately the same time regardless of the location selected; in broader usage, it means that locations can be reached directly, even when their access times differ. “Random” refers to freedom of access order, not to a requirement that locations be selected unpredictably."
    },
    {
      "heading": "Principle and terminology",
      "text": "A random-access system identifies a location using an address, an index, or an offset. A request specifies that location, and the system retrieves or modifies the associated data without traversing the logical sequence from its beginning.\n\nThis differs from sequential access, in which reaching an item generally requires passing through earlier items. Magnetic tape is a characteristic sequential-access medium: reaching a distant record requires moving the tape through intervening positions. An indexed memory location, by contrast, can be selected electronically.\n\nSeveral related expressions describe different aspects of access:\n\n- Random-access capability: whether locations can be selected independently of their sequence.\n- Random-access workload: a pattern of requests to scattered or poorly predictable locations.\n- Direct access: access to a specified record or block without processing all earlier records. This term is often used for disks, whose access times vary with physical position.\n\nTerminology is not entirely uniform. A disk may be described as a random-access device because it supports arbitrary block requests, while a stricter classification distinguishes its position-dependent direct access from the approximately uniform access of semiconductor memory.\n\nRandom access is also unrelated to randomized algorithms: a deterministic program can access memory locations in any order."
    },
    {
      "heading": "Random-access memory",
      "text": "Random-access memory (RAM) takes its name from this addressing capability. A memory controller and addressing circuitry select the cells corresponding to a requested address, rather than searching through stored values in sequence.\n\nTwo major forms are:\n\n- Static random-access memory (SRAM): retains its state while powered without periodic refresh and is widely used in processor caches.\n- Dynamic random-access memory (DRAM): stores information as electrical charge that requires periodic refresh and is widely used for main memory.\n\nRandom access does not imply that memory is writable, volatile, or equally fast under every condition. Read-only memories can support random reads, while both volatile and nonvolatile technologies can provide addressable storage.\n\nActual memory latency depends on the memory hierarchy. A request satisfied by a processor cache is generally faster than one requiring main-memory access. DRAM timing also depends on factors such as whether the requested row is already active, refresh operations, and contention. In non-uniform memory access systems, access time can depend on the memory’s location relative to the requesting processor.\n\nThus, the claim that RAM provides constant-time access is an abstraction useful for analysis, not a guarantee of identical physical latency."
    },
    {
      "heading": "Data structures and computational complexity",
      "text": "Random access is central to indexed data structures. For an array containing fixed-size elements in contiguous storage, the address of element \\(i\\), using zero-based indexing, is\n\n\\[\\operatorname{address}(i)=b+i s,\\]\n\nwhere \\(b\\) is the base address and \\(s\\) is the size of each element in addressable units.\n\nUnder a conventional computational model in which address arithmetic and a memory operation have constant cost, accessing an element by index has time complexity \\(O(1)\\). This result assumes that the requested index is already known. Finding which element satisfies a condition is a separate operation and may require a search.\n\nA linked list does not normally offer constant-time access by numerical position. Reaching its \\(i\\)-th element requires following links from a known node, taking \\(O(i)\\) time when starting at the head. Once a node’s address is known, however, accessing that node need not require traversing the list.\n\nRandom access also affects the efficiency of algorithms. Binary search over a sorted array can examine a middle element directly at each step and complete in \\(O(\\log n)\\) time. Applying the same comparison strategy to a linked list does not automatically provide the same running time, because reaching successive middle positions requires traversal.\n\nVariable-size elements complicate indexed access. Their locations cannot generally be calculated using one fixed stride; efficient access may require a separate table of offsets or another indexing structure.\n\nThe random-access machine model\n\nThe random-access machine is an abstract model used to analyze algorithms. It provides addressable registers or memory locations and a specified collection of basic instructions.\n\nIts cost assumptions matter. In common word-based models, basic operations on words of a bounded size count as constant-time operations. Treating arithmetic on arbitrarily large integers as constant-time would produce different and sometimes unrealistic complexity estimates. Random-access algorithm analysis therefore depends on both the addressing capability and the permitted operations."
    },
    {
      "heading": "Files and storage devices",
      "text": "Files can support random access through operations that read or write at a specified byte offset. An operating system and file system translate that logical position into the relevant storage locations. Some interfaces change a file’s current position before an operation; others specify the offset directly in each request.\n\nA seekable file does not guarantee constant-time physical access:\n\nStorage medium | Arbitrary access characteristics | Important performance factors\nMagnetic tape | Primarily sequential; reaching a distant position requires transport through intervening tape | Positioning distance and streaming behavior\n[[hard-disk-drive | Hard disk drive]] | Supports requests to arbitrary blocks\n[[solid-state-drive | Solid-state drive]] | Supports arbitrary logical block access without mechanical seeking\nSemiconductor main memory | Supports address-based reads and writes | Cache state, memory timing, and contention\n\nSolid-state drives commonly use flash memory, whose read, programming, and erase operations have different granularities and constraints. Supporting arbitrary logical writes does not mean that each write directly overwrites the same physical cells.\n\nLikewise, accessing an arbitrary offset in a compressed or encoded file may require additional processing. Formats with independently decodable blocks and indexes can support efficient seeking; formats dependent on preceding data may require decoding from an earlier restart point."
    },
    {
      "heading": "Performance and applications",
      "text": "The ability to access data randomly should be distinguished from the performance of a random-access workload. A device may support arbitrary requests while handling long sequential transfers much more efficiently.\n\nSequential access often benefits from spatial locality: nearby data are likely to be used together. Hardware and operating systems exploit this through cache-line transfers, prefetching, buffering, and read-ahead. Scattered requests can reduce these benefits and increase the number of transfers needed for the same amount of useful data.\n\nTypical applications include:\n\n- Indexed records: a database index locates selected records without scanning an entire dataset.\n- In-memory lookup: a hash table computes a location or bucket from a key.\n- Interactive media: playback software seeks to selected portions of a recording, subject to the format’s decoding dependencies.\n- Large-file processing: programs access selected file regions through explicit reads or a memory-mapped file.\n\nRandom access can also incur costs hidden by the programming interface. Under virtual memory, an ordinary address-based load may trigger a page fault and require data to be brought into physical memory. In storage systems, many small scattered requests may be limited by latency and the number of operations the device can complete, rather than by its maximum sequential transfer rate.\n\nConsequently, practical evaluation distinguishes access granularity, latency, throughput, read and write behavior, and the distribution of requested locations. A constant-time abstract operation and a fast physical operation are not the same claim."
    }
  ],
  "links": [
    "computer-science",
    "data-structure",
    "randomized-algorithm",
    "static-random-access-memory",
    "memory-hierarchy",
    "cpu-cache",
    "non-uniform-memory-access",
    "array-data-structure",
    "time-complexity",
    "linked-list",
    "binary-search",
    "operating-system",
    "file-system",
    "flash-memory",
    "database-index",
    "hash-table",
    "memory-mapped-file",
    "virtual-memory"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}