
-----------------------------------
Taz
Tue Nov 18, 2008 4:20 pm

Single Random Number?
-----------------------------------
Hiya. I need help with a very simple problem. I did a bit of searching on the forums, but I couldn't find exactly what I was having trouble with.

Actually, it's not even so much a problem.. But.

The idea here is that I'm going to have an amount of people, who would say, write their name on a piece of paper.

All of the papers would then be stuck in a hat, and a single paper would be drawn.

Whoever's name was on the paper wins. really random, and is it being influenced by something?

I want my little lottery program to be as far as possible, because it's actually going to involve real people.

[And to be honest, this doesn't need to be done in Turing. If anyone knows a website or something that would accomplish the same thing for me, that'd be just fine. But I figure I know a tiny bit of turing, so why not try to make it myself?  :D ]

Thanks in advance!

-----------------------------------
Insectoid
Tue Nov 18, 2008 4:45 pm

RE:Single Random Number?
-----------------------------------
Don't use randint (). Jusr don't. Use Rand.Int(). It does basically the same thing, but doesn't require a variable. It's used like so:


put Rand.Int (1, MAX)


This takes one less variable, and does the job better than randint().  A note on variables: The first letter of a variable name cannot be a capital. It must be lower case, though subsequent letters may be upper case.

var foo = good
var Foo = bad
var foO = good
var FoO = bad

-----------------------------------
Taz
Tue Nov 18, 2008 4:55 pm

RE:Single Random Number?
-----------------------------------
Thanks!

But I'm wondering why you say that about the variable names?

It worked fine for me.

-----------------------------------
cavetroll
Tue Nov 18, 2008 5:09 pm

Re: Single Random Number?
-----------------------------------
Well it's not actually random. There is an algorithm that calculates the number (it's pseudo-random). The number it generates is (usually) based off the time the number is generated at. With a computer, it is impossible to have an real random number. The only way (that I know of) is to use radioactive decay.

That being said, the randomness is good enough to be used for something like this. The pattern repeats after something like 2^19937 (depends on the algorithm) iterations. The only time this wouldn't be secure enough would be for something like cryptography.

As for repeated results, if you are running the program really fast over and over again, it's possible it is using the same seed. If you leave a few seconds between each trial, you shouldn't get repeated results other than is statistically probable. If you are, I would try combining a few random numbers together. This would give you more chance for variation.

-----------------------------------
copthesaint
Tue Nov 18, 2008 5:15 pm

RE:Single Random Number?
-----------------------------------
I do recall Rand.Seed Which is Always random.
I'm not possitive if or what the proper code is for turing.

-----------------------------------
cavetroll
Tue Nov 18, 2008 5:17 pm

RE:Single Random Number?
-----------------------------------
Are you sure?

I thought Rand.Seed just let you pick what you used as a seed (as opposed to the default of the time). I figure that this would make it less random.

-----------------------------------
Taz
Tue Nov 18, 2008 5:23 pm

RE:Single Random Number?
-----------------------------------
Thanks a ton, cavetroll. No idea what radioactive decay is, but I appreciate the in-depth response.

You're probably right about the "running the program really fast over and over again" bit. That was most likely the problem there. =D

-----------------------------------
gitoxa
Tue Nov 18, 2008 5:27 pm

Re: RE:Single Random Number?
-----------------------------------
If you were to use the random function multiple times in one execution, they'll return different values.  So unless you're going ot run your program by compiling it to only create one random number per execution, then it should be fine.

As for the variable names, what insectoid said was how his coding conventions are for variable names.  Well, it's a lot of people's on this boards preference. Not everyone uses the same conventions though, for example the ones our teacher likes are:

VariableName
Procedure_Or_Function
CONSTANT
USER_DEFINED_TYPE

Almost any convention is good so long as you stick with it.

-----------------------------------
Taz
Tue Nov 18, 2008 5:41 pm

RE:Single Random Number?
-----------------------------------
Oh, I understand.

It's about consistency, right?

I guess I've never wrote anything that had much to it. Usually a variable or 3, as I'm just learning, really. =D

-----------------------------------
Jack140
Tue Nov 18, 2008 6:04 pm

Re: Single Random Number?
-----------------------------------
I hope this kind of helps...
You just have to make more variables for the amount of people who is involved...




var i : int 
var MAX : int 
var name1 : string %Names of people
var name2 : string
var name3 : string

put "How many Participants are there? : ".. %Get the names of your participants
get MAX
put "Name of a participant(#1)"..
get name1
put "Name of Second Participant (#2)"..
get name2
put "Name of Third Participant(#3)"..
get name3
put "and the winner is... (drum roll please...)"
delay (2500) %Hear heart beats pounding across the room, lol
randint ( i, 1, MAX )
put "The winner is ", i,"!" %Outcomes the results

-----------------------------------
andrew.
Tue Nov 18, 2008 6:26 pm

RE:Single Random Number?
-----------------------------------
var num_of_people : int
put "How many people are in this draw?"
get num_of_people
var names : array 1..num_of_people of string
cls
for i : 1..num_of_people
   put "Contestant #"+i+", what is your name?"
   get names (i)
   cls
end for
var winner : string :=  names (Rand.Int (1, num_of_people))
put "The winner is... "+winner+"! Congrats!"

Since this isn't for school I suppose I can give you the code.

-----------------------------------
copthesaint
Tue Nov 18, 2008 8:53 pm

Re: Single Random Number?
-----------------------------------
That's good andrew but you made 1 mistake ohh well

var num_of_people : int 
put "How many people are in this draw?" 
get num_of_people 
var names : array 1..num_of_people of string 
cls 
for i : 1..num_of_people 
   put ("Contestant #"),i, (", what is your name?" )% 