473,782 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

running a random function

I would like to write some code that would randomly select a function from a
list of functions and call it. I was looking in the globals names space and
randomly selecting items that were of type function.. but I didn't see a
way of actually running the function.

Any pointers?

--
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
Jun 7 '07
12 1476
On 2007-06-07, Dustan <Du**********@g mail.comwrote:
On Jun 7, 1:30 pm, Neil Cerutti <horp...@yahoo. comwrote:
>On 2007-06-07, Stebanoid <Steban...@gmai l.comwrote:
if you have a list of functions you can try this:
import random
import math
m[int(math.floor( len(m)*random.r andom()))]() # seems like Lisp

Or rather m[random.randint( 0, len(m))]()

Or rather random.choice(m )() # seems like Python
Sweet!

--
Neil Cerutti
Jun 7 '07 #11
On 8 , 00:07, Dustan <DustanGro...@g mail.comwrote:
On Jun 7, 1:30 pm, Neil Cerutti <horp...@yahoo. comwrote:
On 2007-06-07, Stebanoid <Steban...@gmai l.comwrote:
if you have a list of functions you can try this:
import random
import math
m[int(math.floor( len(m)*random.r andom()))]() # seems like Lisp
Or rather m[random.randint( 0, len(m))]()

Or rather random.choice(m )() # seems like Python
--
Neil Cerutti
Caution: Cape does not enable user to fly. --Kenner's Batman costume
Sorry.... :(
I have no experience using this module in Python, and forget this
functions because I newer use this.

Sorry for my terrible English. :P

Jun 8 '07 #12
On 2007-06-08, Stebanoid <St*******@gmai l.comwrote:
On 8 , 00:07, Dustan <DustanGro...@g mail.comwrote:
>On Jun 7, 1:30 pm, Neil Cerutti <horp...@yahoo. comwrote:
On 2007-06-07, Stebanoid <Steban...@gmai l.comwrote:
if you have a list of functions you can try this:
import random
import math
m[int(math.floor( len(m)*random.r andom()))]() # seems like Lisp
Or rather m[random.randint( 0, len(m))]()

Or rather random.choice(m )() # seems like Python
--
Neil Cerutti
Caution: Cape does not enable user to fly. --Kenner's Batman costume

Sorry.... :(
I have no experience using this module in Python, and forget
this functions because I newer use this.

Sorry for my terrible English. :P
No need to apologise. My solution above wasn't the best one
posted either!

--
Neil Cerutti
Jun 8 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
2982
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
3
5030
by: TaTonka | last post by:
hi! how can i manage it (html or jscript with css) that everytime a user loads or refreshes a page, the page has a new bgcolor. i want to put it in a single file, so that all my pages have the same color, but after every refresh a new random one. thanx 4 your support
8
3040
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to what I really should do. I've had a look through Programming Python and the Python Cookbook, which have given me ideas, but nothing has gelled yet, so I thought I'd put the question to the community. But first, let me be a little more detailed...
4
8250
by: Greg Strong | last post by:
Hello All, Is it possible to create multiple random numbers in a query where there are numerous records? I've created a custom function. When I use it in a query it creates the same random number for ALL the records. It appears the function is only getting called once, therefore only one random number is being generated for all the records. I want a different random number for each record. Is this possible, or do I have to do it all...
10
2678
by: Leon | last post by:
I know by default the random number generator use the time, but what is the best seed I can used in my web application? The Program generate 6 unique random numbers and load each of them in a textbox control. I need a good seed like ip address or something. 'Function to generate random numbers Public Function GetRandomNumber() As Integer
1
1402
by: muchexie | last post by:
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password. here are the scripts. change_passwd.php <? require_once("system_fns.php"); session_start(); do_html_header("Changing password");
2
2105
by: muchexie | last post by:
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password. here are the scripts. change_passwd.php session_start(); do_html_header("Changing password"); //check_valid_user(); $new_passwd=($_POST);
3
2085
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: ************************************************* Function RandomString(size as integer, lowerCase as boolean) as string Dim builder as StringBuilder = new StringBuilder() Dim random as Random = new Random() Dim i as integer dim ch as char
15
1894
by: ianweise | last post by:
hello, before i post my code for this, is there anyone out there at this moment? no sense in posting if no one is out there to read and answer it =P
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.