Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

random class...

Name: Anonymous 2006-11-07 1:10

guys im trying to create a simulation of the lottery using java... i am makin an array consisting of 5 random numbers ranging from 0 to 9 the thing is i can only get the amount of arrays the class has and everytime i run the application all i get for the 5 random numbers are a bunch of zeros.

this is my code so far...

import java.util.Scanner;
import java.util.Random;
public class Lottery
{
    public static void main (String[] args)
    {
            int[] lotteryNumbers = new int[5];
            int indx;
        int num1, num2, num3, num4, num5;
        Random rand = new Random();
        int sum = 0;
            Scanner key = new Scanner(System.in);
       
        System.out.println("The array size is " +                          lotteryNumbers.length);
        for (indx = 0; indx <5; indx++)
        {
       
                num1 = rand.nextInt(9);
            num2 = rand.nextInt(9);
            num3 = rand.nextInt(9);
            num4 = rand.nextInt(9);
            num5 = rand.nextInt(9);
           
           
            System.out.println(lotteryNumbers[indx]);
          
        }

i forgot to mention the user also has to input his own 5 numbers to see if he won the "grand prize". but i think i have that part down for now... all i am really interested in are those damn 5 random numbers which i cant seem to get right... any help would be appreciated.

Name: Anonymous 2006-11-07 9:26

WTF

IT MIGHT BE RELATED TO HOW YOU NEVER ASSIGN ANYTHING IN THE ARRAY

Name: Anonymous 2006-11-07 10:52

>>2
sage goes in the email field -- it's an NP-complete problem for newbies

Name: Anonymous 2006-11-07 11:15

>>3

It is in the email field, fuckhole

Name: Anonymous 2006-11-07 11:16

>>1

This is the most retarded piece of code I've ever seen.

Name: eff 2006-11-10 2:33

YOu WON!

Name: eff 2006-11-10 2:34

YOu WON!

Name: Anonymous 2006-11-11 7:51

>>6
>>7
for (int i=0;i<2;i++)
{
    puts("YOu WON!");
}

Name: Anonymous 2006-11-11 10:57

const bool youre_a_retard = true;
while (youre_a_retard)
    cout << "You lose!!!" << endl;

Name: Anonymous 2006-11-11 11:07

>>1

You really really suck at coding.

Name: Anonymous 2006-11-13 4:30

>>1
Lol, that's pretty fucked up.

And use Python. See:

import random
a = [random.randint(0, 9) for i in xrange(10)]
print 'The size of the array is', len(a)
print a

It's not a professional enterprise scalable Web 2.0 AJAX XML-based business solution, but I wrote that in 20 seconds and it does what I believe you tried to do in >>1, only it works.

Name: Anonymous 2006-11-13 10:17

import random
a = [random.randint(0, 9) for i in xrange(10)]
perl is superior:
@a=map{int rand 9}0..9;

Name: Anonymous 2006-11-13 12:40

>>12
Superior my ass, the only difference there is rand is pesting the default namespace and Perl lacks lists comprehensions, so you have to do shit with a less clear map and that 0..9 crap. Seriously, this syntax must have been thought of by a 12 year old. Larry Wall needs more Fisher Price, less coming up with crappy syntax.

Name: Anonymous 2006-11-13 14:13

just use Math.random() and remember to multiply by ten and mask as an int.

Name: Anonymous 2006-11-13 14:24

Seriously, this syntax must have been thought of by a 12 year old.

Worse; a Christian.

Name: Anonymous 2006-11-13 15:04

Perl lacks lists comprehensions, so you have to do shit with a less clear map and that 0..9 crap.
yeah, sure, emulating a map with that 'for i in xrange(10)' crap is a lot clearer than just using map in the first place.
and '0..9' seems a lot clearer to me than 'xrange(10)'...

Name: Anonymous 2006-11-13 17:48

>>1
use a real language

Name: Anonymous 2006-11-13 19:59

>>1
Stop saying "create". That's asinine. It's like saying "get" when you mean "procure", or "take", or "become". The proper word in this instance is "write", as in programs or articles or books or fucking world4ch comments.

Name: Anonymous 2006-11-13 20:42

>>1
Ah, you have to generate the random numbers from a rule 30 cellular automata.

Name: Anonymous 2006-11-13 21:22 (sage)

>>18
It's not asinine. It's like 'creating a story'. Works just as well as 'writing'.

Name: Anonymous 2006-11-14 6:36

>>16
List comprehensions don't emulate map. To do the same as a map is a small particular use (not at all the only one) of them. I agree that xrange is a bad name, but range is slower because it creates an actual list (xrange is a generator). As for 0..9, it's intuitive in a piece of text, but in a program, it's counter-intuitive, as you introduce yet another feature, yet another operator, yet another plethora of syntactic and precedence issues, etc.

Name: Anonymous 2006-11-14 8:20

>>21
Perl sucks, Python is a shitty ripoff of Perl with a couple of random features from Haskell. End of discussion.

Name: Anonymous 2006-11-14 9:37

>>13
There are many ways to do things in Perl. A good choice is to pick the most readable choise. Does this look better?

my @numbers;
push @numbers, int(rand(9)) for (1..5);
print "The size of the array is $#numbers\n", @numbers;

Name: Anonymous 2006-11-14 15:44

by the request, it's obvious this is for a class, in which case all these perl Vs python shit is moot.

OP, look through the Math class in the API, and just use Math.random()

Name: Anonymous 2006-11-14 16:22

using System;
class Lottery
{
    static void Main()
    {
        int[] num = new int[5];
        Random rand = new Random();
        for (int i = 0; i < 5; i = i + 1)
        {
            while (num[i] == 0)
            {
                num[i] = rand.Next(9);
            }

            Console.WriteLine("Ball number " +i +" is " +num[i]);
           
        }
        Console.ReadLine();
    }
}

It's in C# so I don't know how useful it will be for you.

Name: Anonymous 2006-11-14 16:45 (sage)

>>25
I hope that's intentionally stupid. But it probably isn't.

Name: Anonymous 2006-11-14 16:50

Hello thar, I did your homework. You should ignore this post if you want to learn anything.

A question: Does Java have anything like the join function in Perl (implode in PHP)? That extra for loop was pain.

import java.util.Random;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Lottery  {
    public static void main(String[] args) throws Exception {
        int[] numbers = new int[5];
        Random rand = new Random();
        BufferedReader br = new BufferedReader(
                    new InputStreamReader(System.in));

        System.out.println("The array size is " + numbers.length);
       
        // generate lottery ticket
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = rand.nextInt(9);
            System.out.print(numbers[i]);
        }

       
        // get users ticket
        System.out.print("\nEnter your numbers: ");
        String user_ticket = br.readLine();

        // check if they match
        String winner_ticket = "";
        for (int i = 0; i < numbers.length; i++) {
            winner_ticket = winner_ticket + numbers[i];
        }

        if (winner_ticket.equals(user_ticket)) {
            System.out.println("You won the grand prize!!");
        }
        else {
            System.out.println("Someone on the internet did my homework :(");
        }
    }
}

Name: Anonymous 2006-11-14 18:18

else {SOP}
I lol'd

Name: Anonymous 2006-11-15 6:02

bump

Name: Anonymous 2006-11-17 7:03

Use Python faggot

Name: Anonymous 2010-09-21 13:14

Random class isn't really random. Also, Java sucks.

Name: Anonymous 2010-09-21 16:23

Java is one of the few languages that actually makes me fucking angry, and I don't even use it, ever.

Name: Anonymous 2010-09-21 16:29

>>33
Fuck, /prog/ needs a delete button.  I didn't see that this asshole >>32 was bumping another 2006 thread.  Well, I still think Java sucks dong.

Name: Anonymous 2011-02-03 4:17

Name: Sgt.Kabu䟒�kimanɢ젓 2012-05-28 20:50

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List