Sponsored Content
Operating Systems OS X (Apple) Generate a random number in a fully POSIX compliant shell, 'dash'... Post 303043121 by Neo on Saturday 18th of January 2020 11:56:50 PM
Old 01-19-2020
Quote:
Originally Posted by wisecracker
Looking forwards to input from the big guns to improve upon it...
Thanks so much for posting these kinds of projects. I wish everyone would do this, regardless of their skill level. Sharing is the operative word these days.

On a similar note:

In 2020, I prefer we call on less experienced users to ask questions about code, versus the "old style from before 2019" of asking "experts" and "heavy hitters" to improve code.

One of my main goals at unix.com in 2020 is to encourage new users and people with less experience to feel good about asking questions and coding, even if they make a lot of mistakes, and their code is not "pretty", versus promoting "better, cleaner, shorter, standards-based code"......

If we have an environment for the "big guns" or the less than 1% or even 0.1% (or less), this will discourage the 99.9% of people (or more) who are not "big guns"...

I'm trying hard to refocus the site away from "elitism" as was the focus for the past number of years (by evolution, not be design), and toward "sharing", especially for beginners and those who may not normally feel comfortable sharing their code and projects with "experts" or "big guns". This also applies to the latest tech (not legacy tech), where everyone is learning together.

"Learn By Sharing Regardless of Your Skill Level"

Thanks so much!
These 2 Users Gave Thanks to Neo For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

How to generate a random number?

How to generate a random integer with specific range(for example, from 1 to 1000)? Also, how to convert a floating point number into a integer? (2 Replies)
Discussion started by: MacMonster
2 Replies

2. Shell Programming and Scripting

generate random number in korn shell

I want to be able to generate a random number within a korn shell script.. Preferably i would like to be able to state how many digits should be in this random number... ie 4 digits or 5 digits etc Any ideas? (2 Replies)
Discussion started by: frustrated1
2 Replies

3. Shell Programming and Scripting

generate random number in perl

Could any one tell how can I generate random number from (0, 100..200) in perl? Thanks! (2 Replies)
Discussion started by: zx1106
2 Replies

4. Programming

Generate random number

I saw this formula to generate random number between two specified values in shell script.the following. $(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)) Give a example in book. Generate random number between 6 and 30.like this. $(((RANDOM%30/3+1)*3)) But I have a... (1 Reply)
Discussion started by: luoluo
1 Replies

5. Shell Programming and Scripting

Unix random number generate in given range

Hi All, I have extracted some report from database for few activities done. Now I have a requirement to add some random time(In range of 10-35) in front of each activity. Can be generated random numbers in any bash/sh shell within a given number range, let's say in between 10-30. ... (10 Replies)
Discussion started by: gr8_usk
10 Replies

6. Shell Programming and Scripting

Logical expression in POSIX compliant Korn Shell

Hi, i want to check if a variable var1 is not a or b or c pseudo code: If NOT (var1 = a or var1 = b or var1 = c) then ... fi I want to use POSIX complaint Korn shell, and for string comparison For the following code, logical.sh #!/usr/bin/ksh var="j" echo "Var : $var" if ! { || ||... (12 Replies)
Discussion started by: ysrini
12 Replies

7. UNIX for Dummies Questions & Answers

how to generate random number as as the first column of a txt file

Dear all, I have a question. I have a txt file say 4000 rows X 1800 Column. I 'd like to creat a new column as the first column which is a column of random numbers (n=4000) thanks a lot! Lin (2 Replies)
Discussion started by: forevertl
2 Replies

8. Shell Programming and Scripting

Help with generate a pair of random number

Hi, Is anybody experience generate a pair of random number by using awk command? I wanna to generate a pair of random number (range from 1 to 4124) and repeats it 416 times. Desired output 2 326 123 1256 341 14 3245 645 . . . I did write the below command: awk... (5 Replies)
Discussion started by: perl_beginner
5 Replies

9. Shell Programming and Scripting

Generating a POSIX random number?

Hi Guys and gals... As you know I am getting to grips with POSIX and hit this stumbling block. Generating two random numbers 0 to 255 POSIXly. Speed in not important hence the 'sleep 1' command. I have done a demo that works, but it sure is ugly! Is there a better way? #!/bin/sh # Random... (12 Replies)
Discussion started by: wisecracker
12 Replies

10. Shell Programming and Scripting

Q: Is SQRT(n) possible in a POSIX compliant shell? A: Yes within limits.

Hi all... This is just a fun project to see if it is possible to get a square root of a positive integer from 1 to 9200000 to 6 decimal places on a 64 bit architecture machine. It is coded around dash and the results show the values from 0 to 10000. Complex numbers can easily be catered for by... (3 Replies)
Discussion started by: wisecracker
3 Replies
Bigarray(3)							   OCaml library						       Bigarray(3)

NAME
Bigarray - Large, multi-dimensional, numerical arrays. Module Module Bigarray Documentation Module Bigarray : sig end Large, multi-dimensional, numerical arrays. This module implements multi-dimensional arrays of integers and floating-point numbers, thereafter referred to as ``big arrays''. The implementation allows efficient sharing of large numerical arrays between OCaml code and C or Fortran numerical libraries. Concerning the naming conventions, users of this module are encouraged to do open Bigarray in their source, then refer to array types and operations via short dot notation, e.g. Array1.t or Array2.sub . Big arrays support all the OCaml ad-hoc polymorphic operations: -comparisons ( = , <> , <= , etc, as well as Pervasives.compare ); -hashing (module Hash ); -and structured input-output (the functions from the Marshal module, as well as Pervasives.output_value and Pervasives.input_value ). === Element kinds === === Big arrays can contain elements of the following kinds: - IEEE single precision (32 bits) floating-point numbers (Bigar- ray.float32_elt), - IEEE double precision (64 bits) floating-point numbers (Bigarray.float64_elt), - IEEE single precision (2 * 32 bits) floating-point complex numbers (Bigarray.complex32_elt), - IEEE double precision (2 * 64 bits) floating-point complex numbers (Bigar- ray.complex64_elt), - 8-bit integers (signed or unsigned) (Bigarray.int8_signed_elt or Bigarray.int8_unsigned_elt), - 16-bit integers (signed or unsigned) (Bigarray.int16_signed_elt or Bigarray.int16_unsigned_elt), - OCaml integers (signed, 31 bits on 32-bit architectures, 63 bits on 64-bit architectures) (Bigarray.int_elt), - 32-bit signed integer (Bigarray.int32_elt), - 64-bit signed integers (Bigar- ray.int64_elt), - platform-native signed integers (32 bits on 32-bit architectures, 64 bits on 64-bit architectures) (Bigar- ray.nativeint_elt). Each element kind is represented at the type level by one of the abstract types defined below. === type float32_elt type float64_elt type complex32_elt type complex64_elt type int8_signed_elt type int8_unsigned_elt type int16_signed_elt type int16_unsigned_elt type int_elt type int32_elt type int64_elt type nativeint_elt type ('a, 'b) kind To each element kind is associated an OCaml type, which is the type of OCaml values that can be stored in the big array or read back from it. This type is not necessarily the same as the type of the array elements proper: for instance, a big array whose elements are of kind float32_elt contains 32-bit single precision floats, but reading or writing one of its elements from OCaml uses the OCaml type float , which is 64-bit double precision floats. The abstract type ('a, 'b) kind captures this association of an OCaml type 'a for values read or written in the big array, and of an ele- ment kind 'b which represents the actual contents of the big array. The following predefined values of type kind list all possible associ- ations of OCaml types with element kinds: val float32 : (float, float32_elt) kind See Bigarray.char . val float64 : (float, float64_elt) kind See Bigarray.char . val complex32 : (Complex.t, complex32_elt) kind See Bigarray.char . val complex64 : (Complex.t, complex64_elt) kind See Bigarray.char . val int8_signed : (int, int8_signed_elt) kind See Bigarray.char . val int8_unsigned : (int, int8_unsigned_elt) kind See Bigarray.char . val int16_signed : (int, int16_signed_elt) kind See Bigarray.char . val int16_unsigned : (int, int16_unsigned_elt) kind See Bigarray.char . val int : (int, int_elt) kind See Bigarray.char . val int32 : (int32, int32_elt) kind See Bigarray.char . val int64 : (int64, int64_elt) kind See Bigarray.char . val nativeint : (nativeint, nativeint_elt) kind See Bigarray.char . val char : (char, int8_unsigned_elt) kind As shown by the types of the values above, big arrays of kind float32_elt and float64_elt are accessed using the OCaml type float . Big arrays of complex kinds complex32_elt , complex64_elt are accessed with the OCaml type Complex.t . Big arrays of integer kinds are accessed using the smallest OCaml integer type large enough to represent the array elements: int for 8- and 16-bit integer bigarrays, as well as OCaml-integer bigarrays; int32 for 32-bit integer bigarrays; int64 for 64-bit integer bigarrays; and nativeint for platform-native integer bigarrays. Finally, big arrays of kind int8_unsigned_elt can also be accessed as arrays of characters instead of arrays of small integers, by using the kind value char instead of int8_unsigned . === Array layouts === type c_layout See Bigarray.fortran_layout . type fortran_layout To facilitate interoperability with existing C and Fortran code, this library supports two different memory layouts for big arrays, one compatible with the C conventions, the other compatible with the Fortran conventions. In the C-style layout, array indices start at 0, and multi-dimensional arrays are laid out in row-major format. That is, for a two-dimen- sional array, all elements of row 0 are contiguous in memory, followed by all elements of row 1, etc. In other terms, the array elements at (x,y) and (x, y+1) are adjacent in memory. In the Fortran-style layout, array indices start at 1, and multi-dimensional arrays are laid out in column-major format. That is, for a two-dimensional array, all elements of column 0 are contiguous in memory, followed by all elements of column 1, etc. In other terms, the array elements at (x,y) and (x+1, y) are adjacent in memory. Each layout style is identified at the type level by the abstract types Bigarray.c_layout and fortran_layout respectively. type 'a layout The type 'a layout represents one of the two supported memory layouts: C-style if 'a is Bigarray.c_layout , Fortran-style if 'a is Bigar- ray.fortran_layout . === Supported layouts The abstract values c_layout and fortran_layout represent the two supported layouts at the level of values. === val c_layout : c_layout layout val fortran_layout : fortran_layout layout === Generic arrays (of arbitrarily many dimensions) === module Genarray : sig end === One-dimensional arrays === module Array1 : sig end One-dimensional arrays. The Array1 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of one-dimensional arrays. (The Array2 and Array3 structures below provide operations specialized for two- and three-dimensional arrays.) Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking. === Two-dimensional arrays === module Array2 : sig end Two-dimensional arrays. The Array2 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of two-dimensional arrays. === Three-dimensional arrays === module Array3 : sig end Three-dimensional arrays. The Array3 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of three-dimensional arrays. === Coercions between generic big arrays and fixed-dimension big arrays === val genarray_of_array1 : ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given one-dimensional big array. val genarray_of_array2 : ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given two-dimensional big array. val genarray_of_array3 : ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given three-dimensional big array. val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t Return the one-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly one dimension. val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t Return the two-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly two dimensions. val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t Return the three-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly three dimensions. === Re-shaping big arrays === val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t reshape b [|d1;...;dN|] converts the big array b to a N -dimensional array of dimensions d1 ... dN . The returned array and the original array b share their data and have the same layout. For instance, assuming that b is a one-dimensional array of dimension 12, reshape b [|3;4|] returns a two-dimensional array b' of dimensions 3 and 4. If b has C layout, the element (x,y) of b' corresponds to the element x * 3 + y of b . If b has Fortran layout, the element (x,y) of b' corresponds to the element x + (y - 1) * 4 of b . The returned big array must have exactly the same number of elements as the original big array b . That is, the product of the dimensions of b must be equal to i1 * ... * iN . Otherwise, Invalid_argument is raised. val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t Specialized version of Bigarray.reshape for reshaping to one-dimensional arrays. val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t Specialized version of Bigarray.reshape for reshaping to two-dimensional arrays. val reshape_3 : ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.t Specialized version of Bigarray.reshape for reshaping to three-dimensional arrays. OCamldoc 2014-06-09 Bigarray(3)
All times are GMT -4. The time now is 12:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy