RandomBasedArrays.jl icon indicating copy to clipboard operation
RandomBasedArrays.jl copied to clipboard

Hassle-free arrays: the first index is always random

RandomBasedArrays

Build Status Build Status Codecov Coveralls

Introduction

image

Image credit: "xkcd: Donald Knuth" (CC-BY-NC 2.5)

RandomBasedArrays.jl is a hassle-free package in the Julia programming language for dealing with arrays: every time you access an element of an array, the first index is random, so you don’t have to remember whether Julia uses 0- or 1-based indexing: you simply cannot ever know what the initial element will be.

Installation

The latest version of RandomBasedArrays.jl is available for Julia v1.0 and later releases, and can be installed with Julia built-in package manager. In a Julia session, after entering the package manager mode with ], run the command

pkg> add RandomBasedArrays

Usage

julia> using RandomBasedArrays

julia> A = RandomBasedArray(reshape(collect(1:25), 5, 5))
5×5 Array{Int64,2}:
 15   7   4   2   6
  7  10  10   9  18
  8   7  16   6  13
  2  21  17  13   2
 22   6  18  19  20

julia> A
5×5 Array{Int64,2}:
 15   3   6  12   8
 20   3   6  22   7
 22   2  20  15   7
 18  22  16   1   3
  1   5   6   6  13

julia> A
5×5 Array{Int64,2}:
  8  14   2  18   1
  7  17   8  19   4
 25  17  15   8  15
  6  19  10  23  23
  7   8   1  22  25

julia> A[-35]
6

julia> A[-35]
9

julia> A[-35]
4

julia> A[28,-19] = 42
42

julia> A
5×5 Array{Int64,2}:
 13  16   3  25   9
 23  20  16  18   1
  5  17  21   6   8
  5   3  42  10  13
 25   6  23   4  11

julia> A
5×5 Array{Int64,2}:
  9  25  25   3   3
  4  14   9   7  18
 22  14  13  21   2
 11  12  19  14  19
 19   2  21   2  21

julia> A
5×5 Array{Int64,2}:
 14  42  21  21  25
 14   8  24  13  17
  6   4  23  12   4
 12   6  19  11   8
  6  12   2  18   3

Related projects

License

The RandomBasedArrays.jl package is licensed under the MIT "Expat" License. The original author is Mosè Giordano.