Sponsored Content
Top Forums Programming Missing Logic Looping Through Switch Statement Post 303022580 by RudiC on Monday 3rd of September 2018 03:45:25 AM
Old 09-03-2018
Calling random seed repeatedly is sort of overdoing it - or, in your case, even counterproductive. Do it once at program startup - if at all necessary as the compiler / interpreter may do it for you.

I know you are compiling a (C) program. Just as a hint, man awk explicitly says
Quote:
Srand(expr) is useful for repeating pseudo random sequences.
Code:
awk 'BEGIN {srand(NULL); for (i=1; i<=10; i++) print rand()}'
0.131538
0.755605
0.45865
0.532767
0.218959
0.0470446
0.678865
0.679296
0.934693
0.383502
awk 'BEGIN { for (i=1; i<=10; i++) {srand(NULL); print rand()}}'
0.131538
0.131538
0.131538
0.131538
0.131538
0.131538
0.131538
0.131538
0.131538
0.131538

Although you are calling srand() with a sort of random parameter, the current system epoch time, the execution will be that fast epoch seconds will not change - that's why you lose the random effect.


Just remove the srand() from your function.
These 2 Users Gave Thanks to RudiC For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using getopt with a switch statement

hi all, i have been trying to get a script working that can take in more than one option using getopt. But for some reason, even when i type in a covered option, it skips directly to my error message of "no match." Any ideas of what might be wrong? set - 'getopt frd*: $*' for i in $* do... (6 Replies)
Discussion started by: gammarays
6 Replies

2. Programming

Comapilation error with Switch statement

Hello , How to resolve below compilation error.activity_type is a member of structure and the output from databse will be stored in structure.Expected output wil l be either D or N or C . sample struct format: struct a{ char acAtivity_type; } code: switch (a->activity_type)... (1 Reply)
Discussion started by: jagan_kalluri
1 Replies

3. Shell Programming and Scripting

Tcl switch statement

I am just learning Tcl and there are few things about it that is perplexing me. I have a question about the switch statement. Why are these two switch statements giving me different results? $ cat test_switch.tcl #!/usr/bin/tcl set foo "abc" switch abc a - b {puts "No. 1"} $foo {puts... (2 Replies)
Discussion started by: SFNYC
2 Replies

4. Shell Programming and Scripting

Missing Assigned Variable within logic operator

Hey , I'm trying to perform the following command, however it cannot read the variable assigned earlier. I'm not sure why this happen. Please help thanks while : do echo "what's ur name? (if none just press )" read name changeName = echo $name | sed "s/on/ey/" echo $changeName #this... (8 Replies)
Discussion started by: sexyTrojan
8 Replies

5. Shell Programming and Scripting

Something is wrong with this switch( case statement.

I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code: while : do ... (2 Replies)
Discussion started by: snakemasterAK
2 Replies

6. Emergency UNIX and Linux Support

Looping using cut statement

i want to create loop for below mentioned A1=`echo $obj1 | cut -d "," -f3` A2=`echo $obj1 | cut -d "," -f4` A3=`echo $obj1 | cut -d "," -f5` A4=`echo $obj1 | cut -d "," -f6` A5=`echo $obj1 | cut -d "," -f7` A6=`echo $obj1 | cut -d "," -f8` A7=`echo $obj1 | cut -d "," -f9` A8=`echo $obj1... (3 Replies)
Discussion started by: pasricha.kunal
3 Replies

7. Shell Programming and Scripting

Logic needed to recursive looping in the script

Hello i have a requirement where in a file i will get string. The length could be from 1 to 20. if the string is less than 6 characters ( ex: ABCD) . i need to append 'X' on right hand side to make it 6 characters (ex: ABCDXX). if suppose i get the same string from the file as ABCDXX then i... (5 Replies)
Discussion started by: dsdev_123
5 Replies

8. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

9. UNIX for Dummies Questions & Answers

Looping Logic, Need to implement

I need to implement a looping logic. If then Go to /path1/file* Get all the filename starting with file* and store it in a array count file number and store it in variable like run Ex: I found 3 file with starting file* so my run = 3 means my loop should run three time May be... (1 Reply)
Discussion started by: Nsharma3006
1 Replies
ModPerl::Code(3)					User Contributed Perl Documentation					  ModPerl::Code(3)

NAME
$class::Const - Perl Interface for $class Constants SYNOPSIS
CONSTANTS
EOF my $groups = $data{$class}; for my $group (sort keys %$groups) { print $fh <<"EOF"; ":$group" use $class::Const -compile qw(:$group); The ":$group" group is for XXX constants. EOF for my $const (sort @{ $groups->{$group} }) { print $fh "=head3 C<$class::$const> "; } } print $fh "=cut "; } } sub generate_constants_lookup_doc { my ($data) = @_; while (my ($class, $groups) = each %$Apache2::ConstantsTable) { my $constants = [map { @$_ } values %$groups]; constants_lookup_code_doc($constants, $class, $data); } } sub generate_constants_group_lookup_doc { my ($data) = @_; while (my ($class, $groups) = each %$Apache2::ConstantsTable) { constants_group_lookup_code_doc($class, $groups, $data); } } sub constants_group_lookup_code_doc { my ($class, $groups, $data) = @_; my @tags; my @code; while (my ($group, $constants) = each %$groups) { $data->{$class}{$group} = [ map { my @ifdef = constants_ifdef($_); s/^($constant_prefixes)_?//o; $seen_const{$class}{$_}++; $_; } @$constants ]; } } sub constants_lookup_code_doc { my ($constants, $class, $data) = @_; my (%switch, %alias); %alias = %shortcuts; my $postfix = lc $class; my $package = $class . '::'; my $package_len = length $package; my $func = canon_func(qw(constants lookup), $postfix); for (@$constants) { if (s/^($constant_prefixes)(_)?//o) { $alias{$_} = join $2 || "", $1, $_; } else { $alias{$_} ||= $_; } next unless /^([A-Z])/; push @{ $switch{$1} }, $_; } for my $key (sort keys %switch) { my $names = $switch{$key}; for my $name (@$names) { my @ifdef = constants_ifdef($alias{$name}); push @{ $data->{$class}{other} }, $name unless $seen_const{$class}{$name} } } } sub generate_exports { my ($self, $c_fh) = @_; require ModPerl::WrapXS; ModPerl::WrapXS->generate_exports($c_fh); } # src/modules/perl/*.c files needed to build APR/APR::* outside # of mod_perl.so sub src_apr_ext { return map { "modperl_$_" } (qw(error bucket), map { "common_$_" } qw(util log)); } 1; __END__ NAME
ModPerl::Code - Generate mod_perl glue code SYNOPSIS
use ModPerl::Code (); my $code = ModPerl::Code->new; $code->generate; DESCRIPTION
This module provides functionality for generating mod_perl glue code. Reason this code is generated rather than written by hand include: consistency thin and clean glue code enable/disable features (without #ifdefs) adapt to changes in Apache experiment with different approaches to gluing AUTHOR
Doug MacEachern perl v5.16.2 2011-02-07 ModPerl::Code(3)
All times are GMT -4. The time now is 10:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy