emkornfield commented on a change in pull request #9671: URL: https://github.com/apache/arrow/pull/9671#discussion_r598843616
########## File path: go/parquet/internal/testutils/random.go ########## @@ -0,0 +1,450 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package testutils + +import ( + "math" + "time" + "unsafe" + + "github.com/apache/arrow/go/arrow" + "github.com/apache/arrow/go/arrow/array" + "github.com/apache/arrow/go/arrow/bitutil" + "github.com/apache/arrow/go/arrow/memory" + "github.com/apache/arrow/go/parquet" + + "golang.org/x/exp/rand" + "gonum.org/v1/gonum/stat/distuv" +) + +// RandomArrayGenerator is a struct used for constructing Random Arrow arrays +// for use with testing. +type RandomArrayGenerator struct { + seed uint64 + extra uint64 + src rand.Source + seedRand *rand.Rand +} + +// NewRandomArrayGenerator constructs a new generator with the requested Seed +func NewRandomArrayGenerator(seed uint64) RandomArrayGenerator { + src := rand.NewSource(seed) + return RandomArrayGenerator{seed, 0, src, rand.New(src)} +} + +// GenerateBitmap generates a bitmap of n bits and stores it into buffer. Prob is the probability +// that a given bit will be zero, with 1-prob being the probability it will be 1. The return value +// is the number of bits that were left unset. The assumption being that buffer is currently +// zero initialized as this function does not clear any bits, it only sets 1s. +func (r *RandomArrayGenerator) GenerateBitmap(buffer []byte, n int64, prob float64) int64 { + count := int64(0) + r.extra++ + + // bernoulli distribution uses P to determine the probabitiliy of a 0 or a 1, + // which we'll use to generate the bitmap. + dist := distuv.Bernoulli{P: prob, Src: rand.NewSource(r.seed + r.extra)} + for i := int(0); int64(i) < n; i++ { Review comment: woud it make sense to replace `int(0)` with `int64(0)`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
