# How to generate runif from a union of two intervals?

randomDAG: Generate a Directed Acyclic Graph (DAG) randomly.

Usage
randomDAG(n, prob, lB = 0.1, uB = 1, V = as.character(1:n))
Arguments
n Number of nodes, n ≥ 2.
prob Probability of connecting a node to another node with higher topological ordering.
lB, uB Lower and upper limit of edge weights, chosen uniformly at random, i.e., by
runif(., min=lB, max=uB).
V character vector length n of node names.

``````library(pcalg)
myDAG <- randomDAG(n = 20, prob= 0.2, lB = 0.1, uB = 1)
``````

Now I want to assign edge weights sampled uniformly from [-2,-0.5] U [0.5,2]. How to adjust the code?

``````pos <- seq(0.5,2,0.01)
neg <- pos*-1
the_union <- union(neg,pos)
sample(the_union,20,replace = TRUE)
#>  [1] -1.46  1.54  1.94  0.57  1.31 -1.46  1.73  1.04  1.61  0.59 -0.73 -1.81
#> [13] -1.05  0.87  1.83 -1.73  0.90  0.86 -0.99  1.90
sample(the_union,20,replace = TRUE)
#>  [1] -2.00  1.79  1.31 -0.58  0.87  0.67  0.93 -0.67 -1.52  1.00  1.52  1.42
#> [13]  0.78 -1.01  0.52  1.19 -0.92  1.51  0.58  1.31
``````

Created on 2023-09-05 with reprex v2.0.2