Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Make random numbers

by Eily (Monsignor)
on Dec 06, 2018 at 11:00 UTC ( [id://1226827]=note: print w/replies, xml ) Need Help??


in reply to Make random numbers

Well you need to call rand(1000) 100 times and push the values into @array. You can do that with a for loop

Replies are listed 'Best First'.
Re^2: Make random numbers
by Marshall (Canon) on Dec 07, 2018 at 08:21 UTC
    I did like your post. This should have been enough to get the OP started.

    There are 2 minor details to be addressed. The rand(1000) function will return float values from 0 and never reaching 1000. So we need to chop off the fractional part - that will yield ints from 0..999. To get the desired range, adding a constant offset of 1 will do the job.

    #!/usr/bin/perl use strict; use warnings; print "",int(rand(1000))+1,"\n" for (1..100);

      I'm tempted to argue that the OP didn't mention wanting integer numbers between 1 and 1000 :P, but technically I did understand the same as you until I started thinking about an answer to your post :D. I didn't mention int on purpose for two reasons, I knew it was mentioned in the rand page, and I expected GHMON to come back here for corrections if the first attempt didn't work as expected.

        I think the OP wanted integers (1..1000).
        I also expected a reply with some Perl code and an explanation of why it didn't "work".
        I think we are on the same page...

        If I get a response like "this worked", but it doesn't create an array and I haven't tried to do that...this will fall upon some very deaf ears.

        Update: I am probably not the only Monk who wonders what the OP is going to do with this array of numbers? Geez.. this function is not exactly a masterpiece of Computer Science. I have no idea of how this data will be used.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1226827]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-25 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found