# Generate line function data with noise

**URL:** https://discourse.julialang.org/t/generate-line-function-data-with-noise/88548
**Category:** General Usage
**Created:** [October 11, 2022, 2:32am UTC](https://discourse.julialang.org/t/generate-line-function-data-with-noise/88548 "2022-10-11T02:32:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JosieG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josieg/32/36221_2.png) [@JosieG](https://discourse.julialang.org/u/JosieG)
#### Post date: [October 11, 2022, 2:32am UTC](https://discourse.julialang.org/t/generate-line-function-data-with-noise/88548/1 "2022-10-11T02:32:44Z")

</div>

I would like to assess one dimension reduction method on simulation data. Besides totally random data, I want to simulate a partial random dataset. Right now I can think of one method to generate such data

```julia
rand2 = collect(1:85)
for m in 1:20
v = []
for i in 1:85
    ai = i/m
    bi = rand(Float64)
    pi = i/85
    push!(v, ai+bi*pi)
end
rand2=hcat(rand2,v)
end
rand2 =rand2[:, (1:end) .!= 1]

```

Is there a better way to generate partially random data? Like data points follow line functions but there are noises. Thanks in advance!

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [October 11, 2022, 3:20am UTC](https://discourse.julialang.org/t/generate-line-function-data-with-noise/88548/2 "2022-10-11T03:20:17Z")

</div>

List comprehensions provide this functionality quite nicely. You can easily generate a 2-dimensional matrix by specifying two dimensions to loop over (iterating over the `i`th row and `j`th column):

```julia
rand2 = [i*(1/j+rand()/85) for i=1:85, j=1:20]

```

This doesn’t work so well when one value in the matrix depends on the value of another, but that’s not the case here.
