# Bug in LightGraphs.SimpleGraphs.random\_regular\_digraph

**URL:** <https://discourse.julialang.org/t/bug-in-lightgraphs-simplegraphs-random-regular-digraph/58901>\
**Category:** General Usage\
**Tags:** package\
**Created:** [April 9, 2021, 4:27am UTC](https://discourse.julialang.org/t/bug-in-lightgraphs-simplegraphs-random-regular-digraph/58901 "2021-04-09T04:27:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oko/32/22734_2.png) [@Oko](https://discourse.julialang.org/u/Oko)\
**Post date:** [April 9, 2021, 4:27am UTC](https://discourse.julialang.org/t/bug-in-lightgraphs-simplegraphs-random-regular-digraph/58901/1 "2021-04-09T04:27:02Z")

</div>

I am trying to use LightGraphs.SimpleGraphs.random\_regular\_digraph Method

[random\_regular\_digraph](https://juliagraphs.org/LightGraphs.jl/latest/generators/#LightGraphs.SimpleGraphs.random_regular_digraph-Tuple%7BInteger,Integer%7D)

to create a regular random digraph. Julia version is 1.6.0 on Red Hat Linux. I am running on a single thread. I am very tired tonight but this just look plain wrong

julia\> using LightGraphs

julia\> adjacency\_matrix(random\_regular\_digraph(10, 4))  
10×10 SparseArrays.SparseMatrixCSC{Int64, Int64} with 40 stored entries:  
⋅ 1 1 ⋅ 1 ⋅ ⋅ 1 ⋅ ⋅  
⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅ 1 1 1  
⋅ ⋅ ⋅ 1 ⋅ 1 ⋅ 1 ⋅ 1  
⋅ ⋅ ⋅ ⋅ ⋅ 1 1 1 1 ⋅  
⋅ 1 1 ⋅ ⋅ 1 ⋅ 1 ⋅ ⋅  
⋅ ⋅ ⋅ 1 ⋅ ⋅ 1 1 ⋅ 1  
⋅ ⋅ 1 1 ⋅ ⋅ ⋅ 1 1 ⋅  
⋅ 1 ⋅ ⋅ 1 1 ⋅ ⋅ 1 ⋅  
⋅ ⋅ ⋅ 1 ⋅ 1 1 1 ⋅ ⋅  
⋅ ⋅ 1 1 ⋅ ⋅ ⋅ 1 1 ⋅

Am I hallucinating or in-degrees (column sums) are messed up? I hope I am wrong as usual but in the case, this turns out to be a real bug I would love to work with a package developer to implement the state-of-the-art algorithm. I would be happy to post more references but this would be the starting point

[[1511.01175] Uniform generation of random regular graphs](https://arxiv.org/abs/1511.01175)

Oh, and in case you wonder I tried with Erdos fork of the above package as well.

julia\> using Erdos

julia\> adjacency\_matrix(random\_regular\_digraph(10, 4))  
10×10 SparseArrays.SparseMatrixCSC{Int64, Int64} with 40 stored entries:  
⋅ 1 ⋅ 1 1 ⋅ ⋅ ⋅ 1 ⋅  
⋅ ⋅ 1 ⋅ 1 ⋅ 1 1 ⋅ ⋅  
⋅ 1 ⋅ ⋅ 1 1 ⋅ ⋅ 1 ⋅  
⋅ ⋅ 1 ⋅ 1 ⋅ 1 ⋅ ⋅ 1  
⋅ 1 ⋅ ⋅ ⋅ ⋅ 1 1 ⋅ 1  
⋅ ⋅ 1 1 ⋅ ⋅ 1 ⋅ ⋅ 1  
⋅ 1 1 ⋅ 1 ⋅ ⋅ 1 ⋅ ⋅  
⋅ 1 1 ⋅ 1 ⋅ ⋅ ⋅ 1 ⋅  
⋅ 1 ⋅ ⋅ 1 1 1 ⋅ ⋅ ⋅  
⋅ ⋅ ⋅ ⋅ 1 1 1 1 ⋅ ⋅

---

<div class="post-metadata">

**Author:** ![Oko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oko/32/22734_2.png) [@Oko](https://discourse.julialang.org/u/Oko)\
**Post date:** [April 11, 2021, 3:09am UTC](https://discourse.julialang.org/t/bug-in-lightgraphs-simplegraphs-random-regular-digraph/58901/2 "2021-04-11T03:09:48Z")

</div>

It appears according to one of the core developers of the JuliaLight package that the above is desired behavior of the LightGraph function. I apologize for the bug report. I failed to realize that the output of the JuliaLight function has nothing to do with the definition we use in mathematics: “_A digraph is k-regular if each vertex has in-degree and out-degree k_”.

[https://github.com/JuliaGraphs/LightGraphs.jl/issues/1558](https://github.com/JuliaGraphs/LightGraphs.jl/issues/1558)
